A lightning-fast URL shortener service built with Rust. Turn long, unwieldy URLs into short, memorable links in milliseconds!
- Shorten URLs: Transform
https://this-is-a-very-long-url-that-nobody-wants-to-type.com/with/lots/of/parameters?and=stuff
intoyourdomain.com/abc123
- Custom Short Links: Create your own memorable short URLs (like
yourdomain.com/rust
) - Track Clicks: See how many times your shortened links have been clicked
- API-First: Easy-to-use REST API for all your shortening needs
- Rust + Tokio: For blazing fast, concurrent operations
- Axum: Modern, ergonomic web framework
- SQLite: Lightweight, embedded database (async-ready!)
- Clean Architecture: Handlers → Services → Storage layers
- Rust (latest stable)
- SQLite
-
Clone & Enter
git clone https://github.com/yourusername/rust_url_shortener.git cd rust_url_shortener
-
Set Environment (or use defaults)
cp .env.example .env
-
Launch!
cargo run
-
Enjoy at http://localhost:8080
curl -X POST http://localhost:8080/api/shorten \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/very/long/path"}'
Response:
{
"short_id": "abc123",
"original_url": "https://example.com/very/long/path"
}
curl -X POST http://localhost:8080/api/shorten \
-H "Content-Type: application/json" \
-d '{"url": "https://rust-lang.org", "custom_id": "rust"}'
curl http://localhost:8080/api/stats/rust
Just open http://localhost:8080/rust
in your browser!
The project includes both unit tests and end-to-end API tests to ensure everything works correctly.
cargo test
./test_api.sh
The project uses GitHub Actions to automate testing and quality checks:
- ✅ Unit Tests: All code tests
- 🔌 API Integration Tests: End-to-end API functionality tests
- 📝 Code Formatting: Ensures consistent code style
- 🔍 Clippy Lints: Catches common mistakes and improvements
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ HTTP Layer │────▶│ Services │────▶│ Storage │
│ (Handlers) │◀────│ (Business │◀────│ (Database) │
└─────────────┘ │ Logic) │ └─────────────┘
└─────────────┘
- Redis-based caching layer
- PostgreSQL storage backend
- Analytics dashboard
- Rate limiting
- Link expiration
- Prometheus metrics integration
MIT