Skip to main content

Crate http_provider_macro

Crate http_provider_macro 

Source
Expand description

Generate HTTP client methods from endpoint definitions.

use http_provider_macro::api_client;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
struct User {
    id: u32,
    name: String,
}

api_client!(
    UserApi,
    {
        {
            path: "/users",
            method: GET,
            res: Vec<User>,
        },
        {
            path: "/users/{id}",
            method: GET,
            path_params: UserPath,
            res: User,
        }
    }
);

#[derive(Serialize)]
struct UserPath {
    id: u32,
}

// Usage
let client = UserApi::new(reqwest::Url::parse("https://api.example.com")?, Some(30));
let users = client.get_users().await?;
let user = client.get_users_by_id(&UserPath { id: 1 }).await?;

Macros§

api_client
http_provider