Skip to content

Simple link shortener project written in Django Rest Framework

Notifications You must be signed in to change notification settings

vanya2143/link_shortener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

link_shortener

Link shortener project written in Django Rest Framework

Run

  1. Clone project and create virtualenv
git clone https://github.com/vanya2143/link_shortener.git
cd link_shortener
pip3 install virtualenv
python3 -m venv .env
  1. Activate virtualenv, install requirements and runserver
source .env/bin/activate
pip install -r requirements.txt
python manage.py migrate
python manage.py runserver

Usage

Use curl utility in code examples

Create short link

curl --request POST \
  --header "Content-Type: application/json" \
  --data '{"url":"https://github.com/vanya2143"}' \
  http://localhost:8000/links/

Response

{
  "short_url":"http://localhost:8000/links/ab2ae469/"
}

Get all short links

curl --request GET http://127.0.0.1:8000/links/

Response

{
  "count":1,
  "next":null,
  "previous":null,
  "results":[
    {
      "id":1,
      "url":"https://github.com/vanya2143",
      "short_url":"http://127.0.0.1:8000/links/ab2ae469/"
    }
  ]
}

Follow the link

curl --request GET -I \
     --url 'http://127.0.0.1:8000/links/ab2ae469/'

Response

HTTP/1.1 302 Found
Date: Thu, 25 Mar 2021 13:04:48 GMT
Server: WSGIServer/0.2 CPython/3.8.3
Content-Type: text/html; charset=utf-8
Location: https://github.com/vanya2143

Get all links in csv format

curl --request GET -sLv \
     --url 'http://127.0.0.1:8000/links/export/'

Response

short_url,url
http://127.0.0.1:8000/links/ab2ae469/,https://github.com/vanya2143

Delete short link

curl -v --request DELETE \
  --header "Content-Type: application/json" \
  http://localhost:8000/links/ab2ae469/

Response

HTTP/1.1 204 No Content

About

Simple link shortener project written in Django Rest Framework

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages