Skip to main content

URL Shortener API

Github StackBlitz

This project provides a URL shortening service built with Fiber and Redis.

Tech Stack

Environment Variables

Copy api/.env.example to api/.env and adjust the values:

VariableDefaultDescription
DB_ADDRlocalhost:6379Redis address (host:port)
DB_PASS(empty)Redis password (leave empty if none)
APP_PORT:3000Port the API listens on (include leading colon)
DOMAINlocalhost:3000Public domain used to build the short URL
API_QUOTA10Max API calls per IP per 30-minute window

Quick Start

Redis only (local dev)

Start Redis with Docker Compose:

docker compose up db -d

Copy and edit the env file, then run the API:

cp api/.env.example api/.env
cd api && go run .

Full stack (API + Redis)

docker compose up -d

API Documentation

Endpoint: POST http://localhost:3000/api/v1

Request body

FieldTypeRequiredDescription
urlstringyesThe original URL to shorten
shortstringnoCustom alias (auto-generated if omitted)
expiryintnoExpiry in hours (default: 24)

Response body

FieldTypeDescription
urlstringOriginal URL
shortstringFull short URL including domain
expiryintExpiry in hours
rate_limitintRemaining API calls in current window
rate_limit_resetintMinutes until rate limit window resets

Rate limit: 10 calls per IP every 30 minutes (configurable via API_QUOTA in .env).

curl Examples

Shorten a URL (auto-generated alias):

curl -X POST http://localhost:3000/api/v1 \
-H "Content-Type: application/json" \
-d '{"url": "https://gofiber.io", "expiry": 24}'

Shorten a URL with a custom alias:

curl -X POST http://localhost:3000/api/v1 \
-H "Content-Type: application/json" \
-d '{"url": "https://gofiber.io", "short": "fiber", "expiry": 48}'

Resolve a short URL (browser or curl):

curl -L http://localhost:3000/fiber

Setup