Operational

URL Shortener API

A REST service that turns long URLs into compact base62 short codes and redirects visitors back to the original address, tracking click counts along the way. Links are scoped to their owner using stateless JWT authentication.

Endpoints

Full request and response examples are in the repository README.

POST /api/auth/register Create an account with a bcrypt-hashed password.
POST /api/auth/login Exchange credentials for a signed JWT.
POST /api/shorten · requires auth Shorten a URL and assign it to the caller.
GET /api/urls · requires auth List the caller's links with click counts.
GET /{shortCode} Redirect to the original URL and record the visit.

Try it

Run these in a terminal, or send the same three requests from Postman.

1. Create an account

curl -X POST https://go.adityag.dev/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{"username":"demo_user","password":"demo-password-123"}'

2. Log in to get a token

curl -X POST https://go.adityag.dev/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"username":"demo_user","password":"demo-password-123"}'

→ {"token":"eyJhbGciOiJIUzI1NiJ9..."}

3. Shorten a URL with that token

curl -X POST https://go.adityag.dev/api/shorten \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{"url":"https://example.com/a/very/long/path"}'

→ {"shortUrl":"https://go.adityag.dev/abc"}

Using Postman? Same three requests. Set the body type to raw → JSON, and on the protected routes use the Authorization tab → Bearer Token, pasting the token from step 2. Tokens are valid for 24 hours.

Getting a 429? That is the rate limiter, not a broken API. Register allows 3 attempts per IP and login allows 5, both refilling over a minute or so. Wait a moment and retry.

Built with