This is a solution to the URL shortener project on roadmap.sh : https://roadmap.sh/projects/url-shortening-service
This project is a lightweight URL shortening service built using Django, Django REST Framework, and PostgreSQL. It provides a RESTful API for creating and managing shortened URLs, along with tracking access statistics.
- URL Shortening: Create a compact, unique short code for any given URL.
- Redirection Support: Retrieve and redirect to the original URL using the short code.
- URL Management: Update or deactivate existing shortened URLs.
- URL Deletion: Remove URL mappings when no longer needed.
- Usage Analytics: Monitor how often each shortened URL is accessed along with last accessed time.
- Python 3.8+
uv- Docker & Docker Compose
git clone https://github.com/sudocodedev/url_shortner.git
cd url-shortenerCreate a .env file in the root directory and configure it as follows:
DATABASE_USER=
DATABASE_PASSWORD=
DATABASE_DB=
DATABASE_PORT=
DATABASE_HOST=
VOLUME_PATH=uv sync✨ And vola you are done with the setup!!
docker compose up -duv run manage.py migrateTo enable your counter system, run the custom management command that creates the PostgreSQL sequence:
python manage.py init_counterThis command creates a sequence named url_shortner starting at 1000000000, if it doesn't already exist.
python manage.py runserverVisit: http://localhost:8000
Visit: