An open API service indexing awesome lists of open source software.

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!

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