A powerful and efficient URL shortening service built with Go, Fiber, and Redis. This API allows users to create, manage, and track shortened URLs with rate limiting and IP-based user management.
- ✅ Shorten URLs - Create short, custom URLs
- ✅ Custom Short Codes - Use your own custom identifiers
- ✅ List All URLs - View all URLs created by your IP
- ✅ Get URL Details - Fetch detailed information about specific shortened URLs
- ✅ Delete URLs - Remove URLs you created
- ✅ Auto Expiry - URLs automatically expire after set time (default 24 hours)
- ✅ Rate Limiting - Prevent API abuse with IP-based rate limiting
- ✅ URL Validation - Ensures only valid URLs are shortened
- ✅ Docker Support - Easy deployment with Docker Compose
- Backend: Go (Golang)
- Framework: Fiber v2
- Database: Redis
- Containerization: Docker & Docker Compose
- Validation: govalidator
- Docker & Docker Compose installed
- Go 1.23+ (for local development)
- Redis (handled by Docker)
git clone https://github.com/Bavithbabu/URL-shortner.git
cd URL-shortnerCreate a .env file in the api directory:
DB_ADDR=db:6379
DB_PASS=
APP_PORT=:3000
DOMAIN=http://localhost:3000
API_QUOTA=10docker-compose up -d --buildThe API will be available at http://localhost:3000
docker-compose logs -f apiPOST /api/v1
Create a shortened URL.
Request Body:
{
"url": "https://www.example.com",
"short": "custom",
"expiry": 24
}Parameters:
url(required): The original URL to shortenshort(optional): Custom short code (auto-generated if not provided)expiry(optional): Expiry time in hours (default: 24)
Response:
{
"url": "https://www.example.com",
"short": "http://localhost:3000/custom",
"expiry": 24,
"rate_limit": 9,
"rate_limit_reset": 30
}GET /api/v1/urls
Get all URLs created by your IP address.
Response:
{
"count": 2,
"urls": [
{
"original_url": "https://www.example.com",
"short_code": "custom",
"short_url": "http://localhost:3000/custom",
"created_at": "2025-12-13 15:30:45",
"expires_in": "86400 seconds"
}
]
}GET /api/v1/url/:shortcode
Get detailed information about a specific shortened URL.
Example: GET /api/v1/url/custom
Response:
{
"original_url": "https://www.example.com",
"short_code": "custom",
"short_url": "http://localhost:3000/custom",
"created_by": "172.18.0.1",
"created_at": "2025-12-13 15:30:45",
"expires_in": "86400 seconds"
}DELETE /api/v1/url/:shortcode
Delete a shortened URL (only if you created it).
Example: DELETE /api/v1/url/custom
Response:
{
"message": "URL deleted successfully",
"deleted": "custom"
}Error (unauthorized):
{
"error": "You are not authorized to delete this URL"
}GET /:shortcode
Redirects to the original URL.
Example: GET /custom → Redirects to https://www.example.com
- Default Quota: 10 requests per IP
- Reset Time: 30 minutes
- Rate limit info included in response headers
URL-shortner/
├── api/
│ ├── database/
│ │ └── database.go # Redis connection
│ ├── helpers/
│ │ └── helpers.go # URL validation helpers
│ ├── routes/
│ │ ├── shorten.go # Shorten URL endpoint
│ │ ├── resolve.go # Redirect endpoint
│ │ ├── list.go # List URLs endpoint
│ │ ├── geturl.go # Get URL details endpoint
│ │ └── delete.go # Delete URL endpoint
│ ├── main.go # Application entry point
│ ├── Dockerfile # Docker config for API
│ ├── go.mod # Go dependencies
│ └── .env # Environment variables
├── db/
│ └── Dockerfile # Docker config for Redis
├── docker-compose.yml # Docker Compose configuration
├── .gitignore
└── README.md
- User authentication (JWT)
- Click/visit analytics
- URL preview before redirect
- QR code generation
- Bulk URL shortening
- Custom domains
- API key authentication
Bavithbabu
- GitHub: @Bavithbabu
This project is open source and available under the MIT License.
Contributions, issues, and feature requests are welcome!
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
⭐ Star this repo if you found it helpful!