Skip to main content

route

Attribute Macro route 

Source
#[route]
Expand description

Declare the spec operation a handler implements — the code-side half of cargo soothfast spec check. Stackable for handlers serving several surfaces (REST + GraphQL + MCP).

Spec generation infers the request and response shapes from the handler’s own signature; request, response, status, params and path_params override that for what inference provably cannot see — erased returns, and detached markers whose empty signature says nothing at all.

ⓘ
#[soothfast::route(spec = "specs/openapi.yaml", operation = "getItem",
                 method = "GET", path = "/items/{id}")]
pub fn get_item(id: u64) -> String { ... }

// `impl IntoResponse` erases the type; name it explicitly.
#[soothfast::route(spec = "specs/openapi.yaml", operation = "createItem",
                 method = "POST", path = "/items",
                 response = "Item", status = 201)]
pub async fn create_item(body: Json<NewItem>) -> impl IntoResponse { ... }

// A detached marker states its whole contract. `path_params` types the
// `{placeholder}`s that would otherwise be bare strings.
#[soothfast::route(spec = "specs/openapi.yaml", operation = "listBySector",
                 method = "GET", path = "/sectors/{sector}",
                 params = "SectorQuery", path_params = "sector: Sector",
                 response = "[Item]")]
fn route_list_by_sector() {}