trillium-api 0.3.0

an api handler for trillium.rs
Documentation

🔌 trillium-api — extractor-based API handler

ci crates.io version docs.rs

Extractor-based API layer for Trillium. Wraps an async function into a Handler: the function receives a &mut Conn and a typed value extracted from the request (deserialized body, shared state, route params, etc.) and returns any type that implements Handler.

Example

use trillium_api::{api, Json};
use trillium::Conn;

/// No input, JSON response.
async fn hello(_conn: &mut Conn, _: ()) -> Json<&'static str> {
    Json("hello, world")
}

/// Deserialize a JSON body and echo it back.
async fn echo(
    _conn: &mut Conn,
    Json(body): Json<trillium_api::Value>,
) -> Json<trillium_api::Value> {
    Json(body)
}

let app = (api(hello), api(echo));
// run with your chosen runtime adapter, e.g.:
// trillium_tokio::run(app);

Safety

This crate uses #![forbid(unsafe_code)].

License