A simple and efficient URL shortener built with ⚡ FastAPI, 🐍 Python, and 🛢️ SQLAlchemy.
This app lets you convert long URLs into short ones and redirect users from those short links back to the original site similar to services like Bitly or TinyURL.
- ✅ Create short URLs
- 🔁 Redirect short URLs to original
- 🧪 Includes test using
pytest - 🗃️ Uses SQLite for local storage
- 📦 Run locally or via Docker
- 🔍 API docs with Swagger at
/docs
git clone https://github.com/utsab-345/url-shortener.git
cd apppython -m venv venv
venv\Scripts\activate
pip install -r requirements.txtuvicorn app.main:app --reload
🔗 Open your browser and go to: http://127.0.0.1:8000/docs
Use:
POST /api/short to generate short URLs
GET /{short_link} to redirectdocker build -t app .docker run -d -p 8000:8000 app
🔗 Visit http://localhost:8000/docsThe project uses environment variables via .env file.
DATABASE_URL=sqlite:///D:/fastapi_project/app.db
You can change to PostgreSQL, MySQL, etc., by modifying this variable.
The test case is located in tests/test_main.py.
pytest
Test ensures the /api/short endpoint works and returns a short URL.MIT License © 2025
Thanks to:
💡 FastAPI for the amazing framework
⚙️ SQLAlchemy for the ORM support
🧪 Pytest for easy testing
🙌 You — for checking out this project!Made with ❤️ by [Utsab Dahal]
Let me know if you'd like the `Dockerfile` or `requirements.txt` generated too!