Link shortener project written in Django Rest Framework
- Clone project and create virtualenv
git clone https://github.com/vanya2143/link_shortener.git
cd link_shortener
pip3 install virtualenv
python3 -m venv .env
- Activate virtualenv, install requirements and runserver
source .env/bin/activate
pip install -r requirements.txt
python manage.py migrate
python manage.py runserver
Use curl utility in code examples
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/"
}
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/"
}
]
}
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
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
curl -v --request DELETE \
--header "Content-Type: application/json" \
http://localhost:8000/links/ab2ae469/
Response
HTTP/1.1 204 No Content