A simple and efficient URL shortening service built in Go using Gin. This service shortens long URLs and allows you to retrieve the original URL.
- Shorten long URLs
- Retrieve original URLs from short codes
- Lightweight and fast
-
Clone the repository:
git clone https://github.com/pravo23/url-shortener.git cd url-shortener
-
Build and start the services:
docker-compose up --build
-
Access the application at
http://localhost:9808
.
-
GET /
Returns a service message.
Response:{"message": "The URL Shortener Service!"}
-
POST /shorten
Shortens a URL.
Request Body:{"url": "http://example.com"}
Response:{"shortened_url": "http://short.url/abcd1234"}
-
GET /{shortUrl}
Redirects to the original URL.
Request URL:http://localhost:9808/{shortUrl}
-
Build the application:
go build -o main .
-
Ensure Redis is running locally on port 6379.
-
Set Redis environment variables:
export REDIS_HOST=localhost export REDIS_PORT=6379
-
Run the application:
./main