🔗 Simple URL Shortener
A simple URL shortener built with Rust. Takes long URLs and makes them short for local use.
✨ Features
- 🦀 Built with Rust and Axum
- 🎨 Web interface with Tailwind CSS
- 📊 Basic click tracking
- 🗄️ SQLite database storage
- 🐳 Docker support
🚀 Quick Start
Prerequisites
- Rust 1.80+ (latest stable recommended)
- Git
Installation
-
Clone and run:
git clone <your-repo-url> cd rust-url-shortener cargo run -
Open your browser: Go to
http://localhost:3000 -
Start shortening URLs!
🛠️ Development
# Run tests
cargo test
# Build for production
cargo build --release
# Run the server
cargo run --release
# Run with Docker
docker build -t url-shortener .
docker run -p 3000:3000 url-shortener
📡 How it works
- POST
/api/shorten- Send a URL, get a short code back - GET
/{short_code}- Visit the short URL, get redirected to original - GET
/api/stats- See all your shortened URLs and click counts
Simple as that!
Key Components
- Frontend: Modern web interface with Tailwind CSS
- Backend: Rust web server using Axum framework
- Database: SQLite for persistent storage
- URL Generation: Cryptographically secure random short codes
- Validation: Input validation and sanitization
📁 Project Structure
url-shortener/
├── src/
│ ├── lib.rs # Core URL shortener logic
│ └── main.rs # Web server and API endpoints
├── static/
│ ├── index.html # Web interface
│ └── app.js # Frontend JavaScript
├── tests/
│ ├── integration_tests.rs
│ └── error_handling_tests.rs
├── Cargo.toml # Rust dependencies
├── Dockerfile # Docker configuration
└── README.md
Made with ❤️ and Rust