Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON everywhere #18

Closed
howamith opened this issue May 19, 2024 · 1 comment · Fixed by #36
Closed

JSON everywhere #18

howamith opened this issue May 19, 2024 · 1 comment · Fixed by #36

Comments

@howamith
Copy link
Member

Most error HTTP status returned from the API have a non-JSON body. Everything should respond with JSON since it's a RESTful API!

@howamith
Copy link
Member Author

Turns out Rocket will already respond with JSON when handling errors, providing the request supplies a Accept: application/json header. I've began work on a Fairing, DefaultJSON in feat/json-everywhere, which overrides the Accept header (or provides if it's not supplied) to application/json, which has the effect of making all error responses JSON whilst still letting the main application code respond in whatever it wants (i.e plain/text for the health-check and YAML for the docs).

There is however, the 406 HTTP status code, which is explicitly for when the server cannot respond with any of the MIME types specified in Accept headers, so we could only return with JSON and respond with a 406 if the client won't accept it, however the issue here is that Rocket currently doesn't support letting Fairings terminate or respond to requests in on_request (see the overview for Fairings in the Rocket docs. This is something planned for v0.6 of Rocket, but it's currently blocked with some hacky workarounds suggested (see rwf2/Rocket#749).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant