An example "Django REST framework" JSON Web Token "(JWT)" application.
- Python 3.6+
- Pipenv
- Start Python virtual ENV
pipenv shell
- Install dependencies
pipenv install
- Run database migrations
python manage.py migrate
- Create admin user
python manage.py createsuperuser --username admin
python manage.py runserver
Once the server is running, visit http://127.0.0.1:8000 in your web browser. Now, you should see something like the following:
Note: access the Django admin interface here: http://127.0.0.1:8000/admin. Example:
curl -XPOST http://localhost:8000/api/token/ -H "Content-Type: application/json" -d '{"username": "admin", "password": "password123"}'
...
{"refresh":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTYwMDEwMjU4NywianRpIjoiMjE3NmE1MTNhMTIyNDM5MmEwMTk0NDlhY2ZjNzg0NGIiLCJ1c2VyX2lkIjoxfQ.RjXDUt90_W7t6N-h4P333clLbQ5oDLHSS3suQ56w1_Q","access":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjAwMTAyNTg3LCJqdGkiOiI4ZmY0YjVkMTNmMTY0MDk4YjVmMGE2MmUwMTRhMGUwZSIsInVzZXJfaWQiOjF9.pOof6NyWHSfFVcJrJhpQMlAEzFKpyR9aTj-og_OpVaE"}
curl -XGET http://localhost:8000/api/v1/ -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjAwMTAzMjI2LCJqdGkiOiIzZTJiMWNmMzI1YTc0YjNhOTA2OGEwYWI0Y2IxNWJkMCIsInVzZXJfaWQiOjF9.BPjzsKgIWrgRn-qwjqCklKQ52KEJOnVjPNULE58MbkM"
curl -XGET http://localhost:8000/health_check/?format=json
- Properly installing Python - https://docs.python-guide.org/starting/installation/
- Installing pipenv - https://docs.python-guide.org/dev/virtualenvs/#installing-pipenv
- Django REST Framework - https://www.django-rest-framework.org
- Django REST Framework Simple JWT - https://github.com/davesque/django-rest-framework-simplejwt