API versioning: How to create handlers which return different data based on "Accept" header value #904
leonklingele
started this conversation in
General
Replies: 1 comment
-
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey there 😃
I was wondering what the best way of creating an API is which versions its endpoints by the request
Accept/ responseContent-Typeheader values. Instead of using the version inside the URL (/v1/usersvs./v2/users) I want to follow REST more closely and use a single route (/users) instead. This route then returns different responses depending on which version the client asks for with theAcceptheader.In OpenAPI jargon, I expect Huma to generate a spec like this:
I have seen that this is probably already doable by using a custom
huma.Operationand setting theResponsesfield to include multipleContents (with aContent-Typeas key for the map) which each define aSchemawhich then in turn specifies how the data is going to be returned for the respectiveContent-Typethe client asks for.What would be the best way of doing this? To me this currently looks quite complicated to do, compared to including the version directly inside the route URL.
Any suggestions? :)
Thanks for helping & creating Huma, @danielgtaylor. It definitely rocks!
(Also see https://jsonapi.org/)
Beta Was this translation helpful? Give feedback.
All reactions