High performance, general purpose web server.
- based on high performance Axum web framework
- uses Tower middleware
- Tako web framework optimizations
- built-in OpenAPI support (Swagger UI and Scalar)
use anyhow::Result;
use web_server_rs::{*, prelude::*};
async fn hello() -> Response {
http::Response::builder()
.status(http::StatusCode::OK)
.body(Body::from("Hello World"))
.unwrap()
}
async fn health() -> impl Responder {
Json!({ "status": "healthy" })
}
#[tokio::main]
async fn main() -> Result<()> {
let config: ServerConfig = ServerConfig {
routes: vec![
Route {
method: Method::GET,
path: "/",
handler: handler!(hello),
operation_id: "hello",
summary: "Hello endpoint",
description: None,
tag: "example",
response_code: 200,
response_desc: "OK",
},
Route {
method: Method::GET,
path: "/health",
handler: handler!(health),
operation_id: "health",
summary: "health endpoint",
description: None,
tag: "example",
response_code: 200,
response_desc: "OK",
},
],
address: "0.0.0.0",
port: 3000,
..Default::default()
};
serve(config).await
}