Expand description
The client_api! macro for generating named client wrapper structs.
Instead of calling client.call::<EndpointType>(args) with turbofish
syntax, this macro generates a wrapper struct with a named method for each
endpoint.
§Example
ⓘ
use typeway_client::client_api;
use typeway_core::*;
use typeway_macros::*;
typeway_path!(type UsersPath = "users");
typeway_path!(type UserByIdPath = "users" / u32);
client_api! {
pub struct UserClient;
/// List all users.
list_users => GetEndpoint<UsersPath, Vec<User>>;
/// Get a user by ID.
get_user => GetEndpoint<UserByIdPath, User>;
/// Create a new user.
create_user => PostEndpoint<UsersPath, CreateUser, User>;
}
// Use the generated struct:
let client = UserClient::new("http://localhost:3000").unwrap();
let users = client.list_users(()).await.unwrap();
let user = client.get_user((42u32,)).await.unwrap();