This project is a Django-based URL Shortener API that allows users to shorten URLs, retrieve the original URLs, update or delete shortened URLs, and view statistics for each shortened URL. This is a home takeaway assignment project by Innovaxel.
Maybe the execution won’t work as the free Render DB has likely expired, but you can check out the API docs.
https://url-shortener-1ic7.onrender.com/swagger- Shorten URL: Generate a short URL for a given original URL.
- Redirect URL: Retrieve the original URL using the short URL.
- Update URL: Update the original URL associated with a short URL.
- Delete URL: Delete a short URL.
- Statistics: View statistics such as hit count for a short URL.
-
Clone the repository:
git clone <repository-url> cd <repository-folder>
-
Create a virtual environment and activate it:
python -m venv env source env/bin/activate # On Windows: env\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Run migrations:
python manage.py migrate
-
Collect static files:
python manage.py collectstatic --noinput
-
Start the development server:
python manage.py runserver
- Endpoint:
/shorten/ - Method:
POST - Request Body:
{ "original_url": "https://example.com" } - Response:
{ "short_url": "abc123", "original_url": "https://example.com", "created_at": "2025-04-19T15:23:00Z", "updated_at": "2025-04-19T15:23:00Z", "hit_count": 0 }
- Endpoint:
/<short_url>/ - Method:
GET - Response:
{ "short_url": "abc123", "original_url": "https://example.com", "hit_count": 1 }
- Endpoint:
/update/<short_url>/ - Method:
PUT - Request Body:
{ "original_url": "https://new-example.com" } - Response:
{ "short_url": "abc123", "original_url": "https://new-example.com", "updated_at": "2025-04-20T10:00:00Z" }
- Endpoint:
/delete/<short_url>/ - Method:
DELETE - Response:
204 No Content
- Endpoint:
/statistics/<short_url>/ - Method:
GET - Response:
{ "short_url": "abc123", "original_url": "https://example.com", "hit_count": 10 }
- Gunicorn: Used as the WSGI HTTP server.
- WhiteNoise: Serves static files efficiently.
- Django CORS Headers: Handles Cross-Origin Resource Sharing (CORS).
To run tests, use:
python manage.py testmain_app/models.py: Contains theShortURLmodel.main_app/views.py: Contains API views for URL shortening, redirection, updating, deletion, and statistics.main_app/serializers.py: Serializes and deserializes data for theShortURLmodel.main_app/urls.py: Defines API endpoints.url_shortener_API/settings.py: Configures Django settings, including CORS and static file handling.