#api-client #rest #macro #express #user-id #contact #declaratively

api-client-macro

Declaratively express a REST API client

3 releases

0.1.2 May 16, 2023
0.1.1 May 15, 2023
0.1.0 May 15, 2023

#13 in #express

MIT/Apache

5KB

Usage

A reqwest powered REST API client can be generated using api_client_macro::generate! provided the following syntax.

api_client_macro::generate!(ApiClient, {
    user {
        get_by_id: get "user/{id}" id: &str,
        delete_by_id: delete "user/{id}" id: &str,
        create: post "user",
        list: get "users"
    },
    contact {
        get_by_id: get "contact/{id}" id: &str,
        delete_by_id: delete "contact/{id}" id: &str,
        create: post "contact",
        list: get "contact"
    }
});

After compilation, the following code is available.

fn main() {
    let client = ApiClientBuilder::new("<api-base-url>", None);
    client.contact_create().body("<body>").send().unwrap();
    client.contact_get_by_id("<id>").send().unwrap();
    client.user_list().query(&[("email", "<email>")]).send().unwrap();
}

No runtime deps