Skip to content

URL Shortener

Pure Python URL shortener service using asyncio.

View Source on GitHub

Quick Start

Running the Server

cd url_shortener
uv run python -m url_shortener

Or using Make:

make run

The server starts at http://localhost:8000 by default.

Testing the API

Shorten a URL:

curl -X POST http://localhost:8000/shorten \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com/very/long/path"}'

Response:

{"short_code": "1"}

Redirect to original URL:

curl -I http://localhost:8000/1

Response:

HTTP/1.1 302 Found
Location: https://example.com/very/long/path

Health check:

curl http://localhost:8000/health

Response:

{"status": "healthy", "service": "url_shortener"}

Constraints

  • Package Manager: uv only
  • Testing: pytest with coverage
  • Server: Pure asyncio (no frameworks)
  • Code Quality: Ruff + mypy (strict)
  • Python: 3.12+