A simple URL shortening REST API service built with Go. This project allows you to shorten long URLs, track clicks (planned, in pipeline), and easily redirect visitors using generated short links.
- Shorten long URLs to compact codes
- Redirect users from short codes to original URLs
- Click tracking for each shortened URL (planned, //todo)
- RESTful API endpoints
- Health check and database test endpoints
- Built with modular Go code and uses a PostgreSQL database
- Go (recommended version 1.25+)
- Docker (optional, good to have, for containerized setup)
- PostgreSQL database
git clone https://github.com/VxDant/URLShortener.git
cd URLShortenerYou need a running PostgreSQL instance. Update the connection details as needed, or use the default provided in scripts/migrate.sh.
- Run migrations (requires the
migrateCLI tool):
./scripts/migrate.sh upgo build -o urlshortener .
./urlshortenerThe service should start on port 8080 by default.
docker build -t urlshortener .
docker run -p 8080:8080 urlshortener-
POST /api/v1/shortly/url
Shortens a URL.
Body:{"long_url": "https://your-long-url"} -
GET /api/v1/shortly/urls
List all shortened URLs. -
GET /shortly/{id}
Redirect to the original URL by short code. -
GET /health
Service health check. -
GET /test-db
Simple database operation tests (for development).
Shorten a URL:
curl -X POST -H "Content-Type: application/json" \
-d '{"long_url":"https://example.com"}' \
http://localhost:8080/api/v1/shortly/urlRedirect:
Visit http://localhost:8080/shortly/{short_code} in your browser.
MIT