axum — framework web
IntermédiaireConstruit au-dessus de tokio et hyper, très ergonomique grâce aux extractors.
cargo add axum
use axum::{extract::{Path, State}, routing::{get, post}, Json, Router};
async fn lire(Path(id): Path<u32>) -> Json<Utilisateur> { /* ... */ }
async fn creer(Json(payload): Json<CreerUtilisateur>) -> Json<Utilisateur> { /* ... */ }
#[tokio::main]
async fn main() {
let app = Router::new()
.route("/utilisateurs/{id}", get(lire))
.route("/utilisateurs", post(creer));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}