Skip to main content

Endpoint

Trait Endpoint 

Source
pub trait Endpoint {
    type Response: DeserializeOwned;
    type Params: EndpointParams + Default;
    type Query: EndpointQuery + Default;

    const METHOD: Method;
    const PATH: &'static str;
}
Expand description

Describes a typed API route.

Implement this trait (or use [endpoint!]) and call Client::call.

§Examples

struct GetTodo;

impl Endpoint for GetTodo {
    const METHOD: Method = Method::GET;
    const PATH: &'static str = "/todos/:id";
    type Response = Todo;
    type Params = ();
    type Query = ();
}

#[derive(Deserialize)]
struct Todo { id: u64, title: String }

let client = Client::new("https://jsonplaceholder.typicode.com")?;
let todo: Todo = client.call::<GetTodo>().param("id", 1).send_json().await?;

Required Associated Constants§

Source

const METHOD: Method

HTTP method for this route.

Source

const PATH: &'static str

Path template (may include :param segments).

Required Associated Types§

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§