kpl-derive

Crates.iokpl-derive
lib.rskpl-derive
version
sourcesrc
created_at2025-04-11 13:26:48.827045+00
updated_at2025-04-11 13:26:48.827045+00
descriptionProcedural macros for generating API client code for stock API endpoints
homepage
repository
max_upload_size
id1629824
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`
size0
hanhotfox (hanxuanliang)

documentation

https://docs.rs/kpl-derive

README

kpl-derive

Crates.io Documentation

A Rust procedural macro library for generating API client code for stock API endpoints.

Features

  • ApiEndpoint derive macro for generating API client code
  • Customizable endpoint configuration via attributes
  • Support for different HTTP methods and response types
  • Automatic serialization and deserialization of request parameters and responses

Installation

Add this to your Cargo.toml:

[dependencies]
kpl-derive = "0.1.1"

Usage

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(())
}

Attribute Options

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)
Commit count: 0

cargo fmt