03ba3fb3c23632ba9aeca40d00f3ae241d437102
URL Shortener API
Production-ready URL Shortener built with FastAPI, PostgreSQL, Docker, and Alembic.
Techstack
FastAPI, PostgreSQL, SQLAlchemy 2.0, Alembic, Docker, Pytest and Pydantic v2
Features
Shorten URLs, Redirect, Click tracking, Stats endpoint, Collision handling, 90%+ test coverage, Dockerized and Alembic migrations
Local Setup
cd <your-repo-url>
python3 -m venv venv
source venv/bin/activate
Create .env:
DATABASE_URL=sqlite:///./test.db
BASE_URL=http://localhost:8000
Run:
python -m uvicorn app.main:app --reload --host 0.0.0.0 --port 9995
Then check:
http://localhost:9995
http://localhost:9995/docs
Test Short URL Endpoint:
http://localhost:9995/shorten
Run Tests
pytest --cov=app --cov-report=term-missing
Running Alembic revision
cd <your-repo-url>
alembic revision --autogenerate -m "create urls table"
Running project in Docker container
cd <your-repo-url>
docker compose up --build
Description
Production-ready URL Shortener built with FastAPI, PostgreSQL, Docker, and Alembic.
1.1 MiB
Releases
1
URL Shortener API v1.0.0
Latest
Languages
Python
95.1%
Mako
3.1%
Dockerfile
1%
Makefile
0.8%