Prerequisites
1
Install Rust
2
Create a new project
Create a new Rust binary project:
Add dependencies
Add Axum and Tokio to yourCargo.toml:
Core dependencies
Axum
The main Axum crate provides routing, extractors, and response types.Tokio
Axum requires the Tokio async runtime. At minimum, you need thenet, rt, and macros features:
full feature set is convenient:
Optional features
Axum provides several optional features you can enable based on your needs:JSON support
Enabled by default. ProvidesJson extractor and response:
Macros
Provides derive macros for common patterns:Multipart forms
For handling file uploads:WebSockets
For WebSocket connections:HTTP/2
Enabled by default. For HTTP/2 support:Tower dependencies
Tower
Provides core service abstractions:Tower-HTTP
Provides HTTP-specific middleware:Tower-HTTP provides many useful middleware out of the box. Check the tower-http documentation for the complete list.
Observability
For production applications, add tracing:TraceLayer.
Complete example
Here’s a production-readyCargo.toml:
Verify installation
Test that everything is set up correctly:Next steps
Quickstart
Build your first HTTP server with Axum