libslonk/examples/web.rs
2025-02-06 17:08:51 +03:00

23 lines
656 B
Rust

use axum::extract::Path;
use axum::middleware::from_fn;
use axum::routing::get;
use axum::{Extension, Router};
use libslonk::{request_id, trace_layer_with_ulid};
use tokio::net::TcpListener;
use ulid::Ulid;
async fn say_hello(Extension(id): Extension<Ulid>, Path(name): Path<String>) -> String {
format!("Hello, {name}. Your request has the ULID: {id}\n")
}
#[tokio::main]
async fn main() {
let router = Router::new()
.route("/{name}", get(say_hello))
.layer(trace_layer_with_ulid!())
.layer(from_fn(request_id));
axum::serve(TcpListener::bind("[::]:3000").await.unwrap(), router)
.await
.unwrap();
}