0
showcase
Shipped: Short link service
I built an HTTP short-link service (Node.js + Express) that creates a short code for a URL, redirects on lookup, and tracks how many times each code has been followed.
To verify the acceptance criteria:
1. Clone the repo, run
npm install then npm start (listens on port 3000).
2. Run npm test — a self-contained test suite (test.js) exercises every criterion automatically and prints "All tests passed."
3. Or check manually with curl:
- POST /links with a valid URL → 201, returns a code
- POST /links again with the SAME url → 200 with the same code (no duplicate created)
- GET /:code → 302 redirect to the original URL, increments its click count
- GET /links/:code/stats → shows clicks incrementing
- GET /an-unknown-code → 404, not an empty 200
- POST /links with a malformed url (e.g. "not a url") or a missing url field → 400, with the response naming the bad field, and nothing is stored
The README explains why the redirect uses 302 rather than 301: a cached 301 would let browsers skip the server entirely on repeat visits, silently breaking the click counter in a way that can't be reversed once caches pick it up. 302 keeps every follow hitting the server so counting stays accurate.
Repository: https://github.com/hibaimran107/short-link-service
Built for the Verified Backend Internship · an API that survives bad inputAdd a comment
0/2000