A simple, extensible HTTP server implemented in Rust using async/await (Tokio). This project demonstrates basic HTTP routing, file serving, and request handling, and is suitable for learning or lightweight custom server needs.
- Async TCP Server using Tokio
- Routing with support for dynamic parameters
- Echo endpoint (
/echo/:msg
) - File serving (GET/POST
/files/:filename
) - User-Agent endpoint
- Health check endpoint
- Configurable file directory via CLI flag
- Structured logging
# Clone the repository
$ git clone <repo-url>
$ cd http-server-rs
# Copy .env.example to .env if needed
$ cp .env.example .env
# Build the project
$ cargo build --release
$ cargo run --release -- --directory ./data
- Default address:
127.0.0.1:4221
- Change data directory with
--directory
flag
GET /health
GET /echo/:msg
- Responds with plain text echo of
:msg
parameter
- Responds with plain text echo of
GET /user-agent
- Returns the User-Agent header
GET /files/:filename
- Serves file content from the configured directory
POST /files/:filename
- Saves request body to file in the configured directory
curl http://127.0.0.1:4221/echo/hello
curl -X POST --data 'Hello world' http://127.0.0.1:4221/files/test.txt
curl http://127.0.0.1:4221/files/test.txt
http-server-rs/
├── src/
│ ├── main.rs # Entry point
│ ├── server.rs # Server implementation
│ ├── flags.rs # CLI flag parsing
│ ├── request.rs # HTTP request parsing
│ ├── response.rs # HTTP response building
│ ├── handler/ # Routing & handler logic
│ ├── routes/ # Endpoint implementations
│ └── http/ # HTTP primitives (method, status, version)
├── Cargo.toml # Dependencies
├── .env.example # Example environment config
└── README.md # Project documentation
- tokio
- clap
- dotenv
- env_logger
- log
- anyhow
- regex
- serde / serde_json
- thiserror
See Cargo.toml
for full list and versions.
This project is licensed under the MIT License.