Skip to content

The py-url-shortener API


Py URL Shortener API is a lightweight, high-performance backend service designed to:

  • Shorten long URLs into compact, shareable links.
  • Redirect users to the original URL with proper HTTP status handling.
  • Track clicks and metadata such as IP, user agent, and referer.
  • Optionally, expire URLs after a set period.

Ready to jump right in?

See the API reference for all endpoints.

This application is built with FastAPI, uses PostgreSQL for persistent storage, and leverages Redis (ready for caching, analytics, or rate-limiting). Docker Compose orchestrates the services, and Traefik handles routing and reverse proxy.


You'll use the POST method to the /api/v1/shorten endpoint. Here's an example:

Path: /api/v1/shorten

Method: POST

Request Body - example:

{
  "url": "https://google.com/",
  "expires_in": 3600
}
Response - example:
{
  "short_url": "http://localhost/r/HrTBms",
  "code": "HrTBms",
  "expires_at": "2025-10-21T16:26:30.000Z"
}

A successful response will return the shortened link in the link object.

Go to our API reference to view all available endpoints.