I have an API, those who would access this API would have to pass an authorization token, so my question is how can I get that auth token from headers?
class RealTimeAPI(APIView):
def post(request):
pass
I have an API, those who would access this API would have to pass an authorization token, so my question is how can I get that auth token from headers?
class RealTimeAPI(APIView):
def post(request):
pass
You can use some middleware which will check the headers.use this reference I have implemented these code in Flask, hope it will help for django also.
In check_headers.py (i.e., middleware of the api)
from flask import Response, request
def check_header(funcn):
@wraps(funcn)
def _inner(*args, **kwargs):
print(request.headers)
# your code for checking the api token in the header
return funcn(*args,**kwargs)
return _inner
In app.py
from check_headers import check_header
...
@app.route('/dashboard', methods=['POST'])
@check_header
def get_course_recommendation():
return "dashboard.html"