https://github.com/pushkarm029/rust_url_shortener
Lightning-fast URL shortener service built with Rust. Turn long, unwieldy URLs into short, memorable links in milliseconds!
https://github.com/pushkarm029/rust_url_shortener
axum concurrency http rust sqllite tokio
Last synced: 5 months ago
JSON representation
Lightning-fast URL shortener service built with Rust. Turn long, unwieldy URLs into short, memorable links in milliseconds!
- Host: GitHub
- URL: https://github.com/pushkarm029/rust_url_shortener
- Owner: Pushkarm029
- Created: 2025-04-08T10:08:47.000Z (about 1 year ago)
- Default Branch: dev
- Last Pushed: 2025-04-09T09:41:45.000Z (12 months ago)
- Last Synced: 2025-04-09T10:36:09.184Z (12 months ago)
- Topics: axum, concurrency, http, rust, sqllite, tokio
- Language: Rust
- Homepage:
- Size: 43 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ Rust URL Shortener
A lightning-fast URL shortener service built with Rust. Turn long, unwieldy URLs into short, memorable links in milliseconds!
## โจ What Can It Do?
- **Shorten URLs**: Transform `https://this-is-a-very-long-url-that-nobody-wants-to-type.com/with/lots/of/parameters?and=stuff` into `yourdomain.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
## ๐ง Built With
- **Rust** + **Tokio**: For blazing fast, concurrent operations
- **Axum**: Modern, ergonomic web framework
- **SQLite**: Lightweight, embedded database (async-ready!)
- **Clean Architecture**: Handlers โ Services โ Storage layers
## ๐ฆ Getting Started
### Prerequisites
- Rust (latest stable)
- SQLite
### Quick Start
1. **Clone & Enter**
```bash
git clone https://github.com/yourusername/rust_url_shortener.git
cd rust_url_shortener
```
2. **Set Environment** (or use defaults)
```bash
cp .env.example .env
```
3. **Launch!**
```bash
cargo run
```
4. **Enjoy at http://localhost:8080**
## ๐ API Guide
### Shorten a URL
```bash
curl -X POST http://localhost:8080/api/shorten \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/very/long/path"}'
```
Response:
```json
{
"short_id": "abc123",
"original_url": "https://example.com/very/long/path"
}
```
### Create Custom Short URL
```bash
curl -X POST http://localhost:8080/api/shorten \
-H "Content-Type: application/json" \
-d '{"url": "https://rust-lang.org", "custom_id": "rust"}'
```
### Get Link Stats
```bash
curl http://localhost:8080/api/stats/rust
```
### Use Your Short Link
Just open `http://localhost:8080/rust` in your browser!
## ๐งช Testing
The project includes both unit tests and end-to-end API tests to ensure everything works correctly.
### Unit Tests
```bash
cargo test
```
### API Integration Tests
```bash
./test_api.sh
```
## ๐ CI/CD Pipeline
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
## ๐๏ธ Architecture
```
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ HTTP Layer โโโโโโถโ Services โโโโโโถโ Storage โ
โ (Handlers) โโโโโโโ (Business โโโโโโโ (Database) โ
โโโโโโโโโโโโโโโ โ Logic) โ โโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโ
```
## ๐ฎ Future Improvements
- Redis-based caching layer
- PostgreSQL storage backend
- Analytics dashboard
- Rate limiting
- Link expiration
- Prometheus metrics integration
## ๐ License
MIT