Add Accept
header negotiation to relevant API endpoints
#337
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds server-driven content negotiation logic to API endpoints. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Content_negotiation#server-driven_content_negotiation
This is done by adding a
NegotiateAccept
function in theapi
package, which can be called by handler functions that return specific content types.In cases where the requested content-type is not available, the server will reply with code 406 and an error message:
For now, all handler functions that need to do content-negotiation call the NegotiateAccept function manually. In future, we could look at grouping these handler functions and applying gin middleware to router groups, though this will require some fiddling.
This PR also doesn't handle redirects when a requested content-type is not available, for now it just returns the 406. In future we can look at doing redirects for specific endpoints, but this should (imo) be a separate PR.
closes #328