DevConnectDevConnect
Sign up · Log in
← back to the feed
0
showcase

Shipped: Short link service

I built a short link service with FastAPI and PostgreSQL (SQLAlchemy + Alembic). POST /links takes a URL and returns a 6-character code. GET /links/{code} redirects to the original URL and counts the follow, and GET /links/{code}/stats shows the count without counting it. How to check the criteria (full setup steps are in the README): - Bad input: a malformed URL, an empty body, or a wrong type returns 400 with the field name and location, and nothing is stored. - Unknown code: returns 404 on both the redirect and stats endpoints. - Same URL twice: returns the same code. A unique constraint on the URL backs this up in the database. - Redirect and counting: follows return 302 (not 301, so browsers don't cache it and skip the counter). Each follow adds exactly 1 using one atomic UPDATE. - Code collisions: handled by retrying when the database rejects a duplicate code. - Tests: run "pytest -v" for 12 passing tests against a separate test database. They cover each point above. The work is split across several PRs: validation, create link, redirect and click counting, database, tests, and README. Known limits: no authentication or rate limiting, and the GET /links list endpoint is only a placeholder. Repository: https://github.com/Ramsha-Anwar/short-link-service Built for the Verified Backend Internship · an API that survives bad input
Add a comment
0/2000