A simple URL shortener service built with FastAPI.
- Shorten a long URL
- Redirect using short URL
- Track number of clicks
- In-memory storage (no database)
git clone cd url-shortener
python -m venv venv source venv/bin/activate # Linux/Mac venv\Scripts\activate # Windows
pip install -r requirements.txt
uvicorn app.main:app --reload
Server will start at: http://localhost:8000
curl -X POST "http://localhost:8000/shorten"
-H "Content-Type: application/json"
-d '{"url":"https://www.google.com"}'
Response: { "short_url": "http://localhost:8000/Ab3xYz" }
Open in browser: http://localhost:8000/Ab3xYz
curl http://localhost:8000/stats/Ab3xYz
Response: { "original_url": "https://www.google.com", "clicks": 3 }