kpl-derive 0.1.0

Procedural macros for generating API client code for stock API endpoints
Documentation
  • Coverage
  • 0%
    0 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 15.48 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 300.68 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • hanxuanliang

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)