Skip to content
Advertisement

How to check certain headers exist in each request in Django Rest Framework?

I want to test api_key and secret against all requests of different models. Both fields exist in a table. I am using DefaultRouter which itself creates all CRUD based requests URLs. Will I need to create custom functions to check headers or there is some better way to do it?

Advertisement

Answer

By the name of headers, I assume you want to check those for authentication. Django REST Framework enables you to implement you custom authentication mechanism, you can check here: https://www.django-rest-framework.org/api-guide/authentication/#custom-authentication

After creating your custom authentication, you can set it to be globally used on settings.py or on any endpoint individually.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement