Cookbook / Getting started
Hello, World
A server in a handful of lines. Create a project, add Axeon, and answer your first request.
Every Axeon app starts with a Server. You register routes with get, post and friends, then call listen. Handlers are plain async closures and can return a string, JSON, a status tuple, an Option or a Result: Axeon turns each into a proper response.
cargo new hello && cd hello
cargo add axeon
use axeon::Server;
fn main() {
let mut app = Server::new();
app.get("/", |_req| async { "Hello, World!" });
app.listen("127.0.0.1:3000").expect("server failed to start");
}
cargo run
curl -i http://127.0.0.1:3000/
Notes#
mainis an ordinary synchronous function.listenbuilds a Tokio runtime for you, serves HTTP/1.1 and HTTP/2, and stops cleanly on Ctrl+C or SIGTERM.- Need your own runtime (to connect to a database first, say)? See Production setup for
serve_with_shutdown. - Axeon needs Rust 1.88 or newer.