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§
Required Associated Types§
Sourcetype Response: DeserializeOwned
type Response: DeserializeOwned
JSON response type for EndpointRequestBuilder::send_json.
Sourcetype Params: EndpointParams + Default
type Params: EndpointParams + Default
Path parameters applied via EndpointRequestBuilder::params.
Sourcetype Query: EndpointQuery + Default
type Query: EndpointQuery + Default
Query parameters applied via EndpointRequestBuilder::query.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".