Skip to content
All projects

Project case study

URL Shortener API

A FastAPI service that validates destination URLs, reuses existing mappings, generates collision-checked short codes, and redirects visitors to the original URL.

FastAPISQLAlchemyPydantic
Open source repository

The problem

Turn a submitted URL into a short, reusable link and resolve it with a redirect.

Request flow

  1. 01HTTP request
  2. 02Pydantic URL validation
  3. 03SQLAlchemy mapping lookup
  4. 04HTTP 302 redirect

Example route: GET /shortner/{short_code}

Implementation decisions

  • Validate destinations as HTTP URLs before storing them.
  • Use database uniqueness constraints for original URLs and short codes.
  • Reuse an existing mapping and retry generated six-character codes after collisions.

Validation and failure handling

  • Invalid destinations fail validation.
  • Unknown short codes return 404.