Skip to main content

serve

Macro serve 

Source
macro_rules! serve {
    ($addr:expr, $app:expr $(,)?) => { ... };
}
Available on crate feature http only.
Expand description

Bind an address and serve, until the process is asked to stop.

The last step of every service, and the one with the most ways to be subtly wrong: a server that ignores SIGTERM is killed mid-request on every deploy, so the shutdown signal is wired in rather than left as an exercise.

ⓘ
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let app = ash_jsonapi::router!(App, todos::routes()).with_state(state);
    ash_jsonapi::serve!("0.0.0.0:3000", app).await?;
    Ok(())
}

Yields std::io::Result<()>. Use axum::serve() directly when you need a listener you built yourself, or a different shutdown condition.