URL Shortener

Description

Generates short URLs, redirects to the original URL and counts visitors for each url.

Installation

pip install -r requirements.txt
python manage.py migrate

Usage

Run Server

gunicorn url_shortener.wsgi

Create Short URL

Request

curl -X POST "http://127.0.0.1:8000/shortener/" -H "accept: application/json" -H "Content-Type: application/json" -H "X-CSRFToken: YOUR-CSRF-TOKEN" -d "{ \"url\": \"https://example.com\"}"

Response

{
    "url": "https://example.com",
    "slug": "BXaL",
    "visitor_count": "2020-01-01T00:00:00Z"
}

201 Created

List Short URLs

Request

curl -X GET "http://127.0.0.1:8000/shortener/" -H "accept: application/json" -H "X-CSRFToken: YOUR-CSRF-TOKEN"

Response

[
  {
    "url": "https://example.com",
    "slug": "0GrR",
    "visitor_count": 1
  }
]

200 OK

Redirect to Original URL

Request

curl -X GET "http://127.0.0.1:8000/r/0GrR/"

Response

302 Found

Licence

MIT