A secure and scalable file upload microservice built with Rust and Axum.
✔ File Upload – Supports multipart form uploads
✔ Rate Limiting – Uses Tower-based rate limiting
✔ CORS Support – Configurable cross-origin policies
✔ Health Checks & Metrics – Tracks API uptime and status
✔ Secure JSON Responses – Returns structured metadata
✔ Scalable Architecture – Built with Axum, Tokio, and Tower
| Technology | Purpose |
|---|---|
| Rust 🦀 | High-performance systems programming |
| Axum ⚡ | Async web framework |
| Tokio 🔄 | Async runtime for handling multiple requests |
| Tower 📡 | Middleware for rate limiting & request tracing |
| Serde 📦 | JSON serialization/deserialization |
| tracing 🔍 | Structured logging & monitoring |
/file_microservice
├── src/
│ ├── main.rs # Application entry point
│ ├── handlers/ # Request handlers
│ ├── file.rs # File upload logic
│ ├── health.rs # Health check & metrics
│ ├── middleware/ # Middleware (rate limiting)
│ ├── models/ # Data structures
│ ├── config/ # Application configuration
├── tests/ # Integration tests
├── Cargo.toml # Dependencies
└── README.md # Documentation
- Rust (via Rustup)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shgit clone https://github.com/yourusername/file_microservice.git
cd file_microserviceCreate a .env file:
PORT=3000
MAX_FILE_SIZE=5242880 # 5MBcargo build
cargo runYour API will start at http://localhost:3000 🎉
curl -X POST http://localhost:3000/upload \
-F "upfile=@example.txt"{
"name": "example.txt",
"type": "text/plain",
"size": 1234
}✅ Validates file type and size
✅ Returns metadata about the uploaded file
curl http://localhost:3000/health{
"status": "healthy",
"timestamp": 1700000000
}✅ Useful for monitoring API availability
- Limits API requests per client using Tower middleware
- Headers for Rate Limits:
X-RateLimit-Limit: Max requests allowedX-RateLimit-Remaining: Remaining requests in windowX-RateLimit-Reset: Time (in seconds) until reset
cargo testRun a specific test:
cargo test test_file_upload# Build the project
cargo build
# Run the application
cargo run
# Run tests
cargo test
# Check for compilation errors
cargo check
# Update dependencies
cargo update
# Clean build artifacts
cargo clean- Use cargo watch for auto-reloading:
cargo install cargo-watch cargo watch -x run
- Format code:
cargo fmt
- Check for warnings:
cargo clippy
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
- Blog: dev.to/danielphilipjohnson
- GitHub: github.com/yourusername
If you find this project useful, please star ⭐ the repo and contribute! 🎉