A simple HTTP server built with Rust using the Axum web framework.
- Basic HTTP server with routing
- Async/await support with Tokio
- JSON serialization with Serde
- Logging with Tracing
- GET and POST endpoints
- JSON request/response handling
- Docker support
- Rust (latest stable version)
- Cargo
- Clone or navigate to the project directory
- Run the server:
cargo run
The server will start on http://0.0.0.0:3000
GET /
- Returns "Hello, World!" (plain text)GET /json
- Returns JSON response with messagePOST /post
- Echo JSON endpoint (returns the same JSON body sent)POST /post-validate
- Validates and echoes structured JSON (name: string, age: number)
src/
├── main.rs # Application entry point
└── routers/
├── mod.rs # Router module declarations
└── root/
├── mod.rs # Root module declarations
├── get.rs # GET route handlers
└── post.rs # POST route handlers
- axum - Web framework
- tokio - Async runtime
- tracing - Logging framework
- serde - Serialization framework
Build and run with Docker:
docker build -t http-server .
docker run -p 3000:3000 http-server
To run in development mode with hot reloading, you can use cargo watch
:
cargo install cargo-watch
cargo watch -x run
Test the endpoints:
# GET endpoints
curl http://localhost:3000/
curl http://localhost:3000/json
# POST endpoints
curl -X POST http://localhost:3000/post \
-H "Content-Type: application/json" \
-d '{"test": "data"}'
curl -X POST http://localhost:3000/post-validate \
-H "Content-Type: application/json" \
-d '{"name": "John", "age": 30}'