How to add Accept version header in browesable API? #8449
Replies: 5 comments 2 replies
-
I don't think DRF has a feature for it, and browsers don't generally let you set custom headers (quoted from an SO answer). Searching on StackOverflow (1, 2, 3), it seems using modheader browser extension is a somewhat popular way to add your custom header. However, you could also override the browsable API script to include a custom header yourself. I believe the script lies on https://github.com/encode/django-rest-framework/blob/master/rest_framework/static/rest_framework/js/ajax-form.js. |
Beta Was this translation helpful? Give feedback.
-
Check this https://www.django-rest-framework.org/api-guide/versioning/, usually api version is included in URL param |
Beta Was this translation helpful? Give feedback.
-
I am aware of the docs but from them it says:
"Versioning based on accept headers is generally considered
<http://blog.steveklabnik.com/posts/2011-07-03-nobody-understands-rest-or-http#i_want_my_api_to_be_versioned>
as best practice
<https://github.com/interagent/http-api-design/blob/master/en/foundations/require-versioning-in-the-accepts-header.md>
"
As I want to follow best practices I was hoping the rest framework
browsable API would support this out of the box but I think I will need to
extend it.
I do not wish to have clients using the test harness to install a new
extension to add the header.
…On Tue, 19 Apr 2022, 08:02 voxvici, ***@***.***> wrote:
Check this https://www.django-rest-framework.org/api-guide/versioning/,
usually api version is included in URL param
—
Reply to this email directly, view it on GitHub
<#8449 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANKADFWH26YIVGKYYNRDSLVF2VE5ANCNFSM5S2QLAYA>
.
You are receiving this because you authored the thread.Message ID:
<encode/django-rest-framework/repo-discussions/8449/comments/2593010@
github.com>
|
Beta Was this translation helpful? Give feedback.
-
Thank you - I will look into extending the browsable API and maybe open a
feature request to have it implemented in the core.
Would be good to have the browsable API as close to feature compatible with
what we can build.
…On Tue, 19 Apr 2022, 03:06 hashlash, ***@***.***> wrote:
I don't think DRF has a feature for it, and *browsers don't generally let
you set custom headers* (quoted from an SO answer
<https://stackoverflow.com/a/24403244/7168030>).
Searching on StackOverflow (1
<https://stackoverflow.com/a/44014014/7168030>, 2
<https://stackoverflow.com/a/27012197/7168030>, 3
<https://stackoverflow.com/a/64594311/7168030>), it seems using modheader
<https://chrome.google.com/webstore/detail/modheader/idgpnmonknjnojddfkpgkljpfnnfcklj?hl=en>
browser extension is a somewhat popular way to add your custom header.
However, you could also override the browsable API script to include a
custom header yourself. I believe the script lies on
https://github.com/encode/django-rest-framework/blob/master/rest_framework/static/rest_framework/js/ajax-form.js
.
—
Reply to this email directly, view it on GitHub
<#8449 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANKADCJ5UXGHIOUGMI67ELVFZSPPANCNFSM5S2QLAYA>
.
You are receiving this because you authored the thread.Message ID:
<encode/django-rest-framework/repo-discussions/8449/comments/2591055@
github.com>
|
Beta Was this translation helpful? Give feedback.
-
Yes - I have that implemented thanks.
The question is not how to add versioning to my API but how to get the
built-in browsable API to support this without adding an additional browser
extension.
…On Tue, 19 Apr 2022, 12:01 voxvici, ***@***.***> wrote:
There is every possible way of adding API version within django rest
framework and for your header solution as well
https://www.django-rest-framework.org/api-guide/versioning/#acceptheaderversioning
—
Reply to this email directly, view it on GitHub
<#8449 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANKADDJRYDUGBPYR43XJ2TVF3RGBANCNFSM5S2QLAYA>
.
You are receiving this because you authored the thread.Message ID:
<encode/django-rest-framework/repo-discussions/8449/comments/2594918@
github.com>
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
Trying to build an API using best practices and noticed the recommendation to use an
Accept
header to version my API.However when I try to access my API with the builtin browsable API, I get an invalid version error:
How would I extend the browesable API to include a version header (ideally a user-selectable dropdown version but a hard-coded default latest version would work for now)?
Or what would be the recommended practice here?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions