Changing Content-Type responses in Django Rest Framework?

I need all the error responses in my API to stick to the "Problem Details for HTTP API" Internet project , which in the context of Django Rest Framework could simply mean changing Content-Type JSON responses to "application / problem + json". while successful responses stick to "application / json". What's the best way to accomplish this?

I thought about creating a custom exception handler that would do the following:

  • If "application / problem + json" is not accepted by the client, a "406 Not Acceptable" response is returned.
  • Otherwise, call rest_framework.views: exception_handler () and set the response content type to "application / problem + json". (Let's assume I have a render for this type.)

Is there a better way to do this? If not, can you identify any problems with this approach?

+3
django-rest-framework


source to share


No one has answered this question yet

Check out similar questions:

25
django-rest-framework: api versioning
17
Adding root element to json response (django-rest-framework)
3
Django rest framework, install Content-Encoding api response for gzip
2
Django Rest Framework how to get response from server on request
1
Serve images with django-rest-framework
1
Multipage border in django rest renderer
1
406 is not acceptable in Django Rest Swagger
1
Django Rest Framework - response envelope
0
Getting foreign key value in Django Rest Framework
0
How to manipulate response in django middleware when using django rest framework?



All Articles
Loading...
X
Show
Funny
Dev
Pics