A fast, simple, and lightweight URL shortening service built with Go. This API allows you to create short URLs from long URLs and redirect users to the original URLs.
- Quick URL shortening with short codes
- Automatic redirect to original URLs
- MongoDB persistent storage
- RESTful API
- Go 1.25.3
- Gin web framework
- MongoDB
-
Clone the repository:
git clone https://github.com/Danztee/url-shortener.git cd url-shortener -
Install dependencies:
go mod download
-
Create
.envfile:MONGO_URI=mongodb+srv://username:password@cluster.mongodb.net/?retryWrites=true&w=majority BASE_URL=http://localhost:8080 PORT=8080
go run main.goShorten a URL:
POST /shorten
Content-Type: application/json
{
"original_url": "https://example.com/very/long/url"
}
Response:
{
"short_url": "http://localhost:8080/abc123"
}Redirect to Original URL:
GET /:code| Variable | Description |
|---|---|
MONGO_URI |
MongoDB connection string |
BASE_URL |
Base URL for short URLs |
PORT |
Server port number |
If you have any questions or run into any issues, please open an issue on the GitHub repository.
Made with ❤️ by Danztee