Crates.io | kpl-derive |
lib.rs | kpl-derive |
version | |
source | src |
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 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
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)