| Crates.io | kpl-derive |
| lib.rs | kpl-derive |
| version | 0.1.0 |
| created_at | 2025-04-11 13:26:48.827045+00 |
| updated_at | 2025-04-11 13:26:48.827045+00 |
| description | Procedural macros for generating API client code for stock API endpoints |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1629824 |
| size | 15,485 |
A Rust procedural macro library for generating API client code for stock API endpoints.
ApiEndpoint derive macro for generating API client codeAdd this to your Cargo.toml:
[dependencies]
kpl-derive = "0.1.1"
use kpl_derive::ApiEndpoint;
use serde::{Deserialize, Serialize};
// Define your response type
#[derive(Debug, Deserialize)]
struct MyResponseType {
// Your response fields here
data: String,
}
// Define your API endpoint
#[derive(ApiEndpoint, Serialize)]
#[endpoint(name = "My API Endpoint", method = "GET", path = "/api/endpoint", resp = MyResponseType)]
struct MyApiEndpoint {
// Your request parameters here
#[serde(rename = "param_name")]
param: String,
}
// Use the generated code
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let endpoint = MyApiEndpoint {
param: "value".to_string(),
};
// Execute the API call
let response = endpoint.execute().await?;
println!("Response: {:?}", response);
Ok(())
}
The #[endpoint(...)] attribute supports the following options:
name: A display name for the endpoint (required)method: HTTP method to use (default: "GET")path: API path (default: "/w1/api/index.php")host: API host (default: "apphis.longhuvip.com")resp: Response type (default: serde_json::Value)