shorty-link-api - is a web service for shortening URLs.
- Python 3.9
- Django 4.0.3
- Django REST Framework
- PostgreSQL
New user registration.
Method: POST
Arguments:
usernamepasswordemail
Example:
curl --data "username=new_user&password=yourpassword&email=user@mail.com" http://127.0.0.1:8000/auth/users/Response:
{
"email":"user@mail.com",
"username":"new_user",
"id":1
}Creating a JSON Web Token (JWT).
Method: POST
Arguments:
usernamepasswordemail
Example:
curl --data "username=new_user&password=yourpassword&email=user@mail.com" http://127.0.0.1:8000/auth/jwt/create/Response:
{
"refresh":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTY0OTg3ODgyOCwianRpIjoiMDUyNDRjNTQ5ZGFjNGUzOTlhYTdkODZlOGFlOTNhYjYiLCJ1c2VyX2lkIjo0fQ.fTSNW91hE3a3iNuDGIzPBIIKs6cwrYKjxCFtXeAccpw",
"access":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjQ5NzkyNzI4LCJqdGkiOiI5MzU4MzUwZjA4ZTQ0NDJiYTAzOTNjYmVmMWQyNmNmYiIsInVzZXJfaWQiOjR9.sIrfCNLa_r-mIXsFreEWq2JR1HAGf9abrf-0k3Z6xZA"
}Getting a new JWT after the lifetime of the previously generated one has expired.
Method: POST
Arguments:
refresh: The token that was previously obtained along with the access token.
Example:
curl --data "refresh=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTY0OTg3ODgyOCwianRpIjoiMDUyNDRjNTQ5ZGFjNGUzOTlhYTdkODZlOGFlOTNhYjYiLCJ1c2VyX2lkIjo0fQ.fTSNW91hE3a3iNuDGIzPBIIKs6cwrYKjxCFtXeAccpw" http://127.0.0.1:8000/auth/jwt/refresh/Response:
{
"access":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjQ5NzkzNjY1LCJqdGkiOiIwMDAyMGUwMzQyODQ0NDIxODYzZjA1YWRjNGJkYWM3MCIsInVzZXJfaWQiOjR9.-JJzmdKgKTyjVZG2rzoOguSfUr1UfowQs8ms00MxVDc"
}All API calls will commence with the base URL, /api/v1/.
Getting a list of all shortened links.
Method: GET
Example:
$ curl http://127.0.0.1:8000/api/v1/shortener/Response:
[
{
"id": 2,
"short_url": "http://127.0.0.1:8000/NO1UmLk8tG",
"link": "https://yandex.ru/",
"short_id" :"NO1UmLk8tG",
"created": "2022-04-10T15:58:17.559856Z"
},
{
"id": 1,
"short_url": "http://127.0.0.1:8000/google",
"link": "https://google.com/",
"short_id" :"google",
"created": "2022-04-10T15:54:14.194478Z"
}
]Creating a shortened URL.
Method: POST
Arguments:
link: the URL to shorten (e.ghttps://google.com)short_id(optional): a custom ending for the short URL. If left empty, a short id will be generated automatically.
The link argument must be URL encoded.
Response: A JSON representation of the shortened URL.
Example:
$ curl -H "Accept: application/json" \
-H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjQ5NzkzNjY1LCJqdGkiOiIwMDAyMGUwMzQyODQ0NDIxODYzZjA1YWRjNGJkYWM3MCIsInVzZXJfaWQiOjR9.-JJzmdKgKTyjVZG2rzoOguSfUr1UfowQs8ms00MxVDc" \
-d "link=http://www.yahoo.com/" \
http://127.0.0.1:8000/api/v1/shortener/Response:
{
"id":3,
"short_url":"http://127.0.0.1:8000/IEO37A0ZLu",
"link":"http://www.yahoo.com/",
"short_id":"IEO37A0ZLu",
"created":"2022-04-12T20:04:32.627494Z"
}Update shortened URL.
Method: PUT
Arguments:
linkshort_id
Example:
$ curl -X PUT
-H "Accept: application/json"
-H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjQ5OTY2ODI2LCJqdGkiOiIwYTZkZDA4ODQ3ZmQ0Mzc2YjhjNjJkMTVkODMzYTAzZiIsInVzZXJfaWQiOjR9.jlW3HLyL3aCw-gwiCuIqGR3JeAbuy0wQ9EVGJ7683EU"
-d "link=http://www.yahoo.com/&short_id=example"
http://127.0.0.1:8000/api/v1/shortener/3/Response:
{
"id":3,
"short_url":"http://127.0.0.1:8000/example",
"link":"http://www.yahoo.com/",
"short_id":"example",
"created":"2022-04-12T20:13:00.785387Z"
}Delete shortened URL.
Method: DELETE
Example:
$ curl -X DELETE
-H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjQ5OTY3Mjc5LCJqdGkiOiIyZDgxYjFhNTdlZmM0OGNjOWFkZWU1YzIyYjA4NTM4YSIsInVzZXJfaWQiOjR9.LlaVjUe8t0bSMFaHxq8j4RJwgsAHt_ABjLOU3Si4OL4"
http://127.0.0.1:8000/api/v1/shortener/9/