Skip to main content

endpoint

Macro endpoint 

Source
macro_rules! endpoint {
    (
        $name:ident,
        $method:ident,
        $path:literal,
        Response = $response:ty
    ) => { ... };
    (
        $name:ident,
        $method:ident,
        $path:literal,
        Response = $response:ty,
        Params = $params:ty
    ) => { ... };
    (
        $name:ident,
        $method:ident,
        $path:literal,
        Response = $response:ty,
        Query = $query:ty
    ) => { ... };
    (
        $name:ident,
        $method:ident,
        $path:literal,
        Response = $response:ty,
        Params = $params:ty,
        Query = $query:ty
    ) => { ... };
}
Expand description

Defines a simple Endpoint with optional typed params and query.

§Examples

use better_fetch::{endpoint, define_params};
use serde::Deserialize;

#[derive(Deserialize)]
pub struct Health {
    ok: bool,
}

endpoint!(HealthCheck, GET, "/health", Response = Health);

define_params!(GetTodoParams for "/todos/:id" { id: u64 });
endpoint!(GetTodo, GET, "/todos/:id", Response = Health, Params = GetTodoParams);