Search code examples
resthttpbackend

HTTP Status >= 300 Returning JSON


I was wondering if it is acceptable/common to have a server return a JSON response along side a 3xx or 4xx response?

The reason I ask this is because I do return a JSON response with more details regarding the error, but it seems the engine I am using doesn't agree with what I am doing. I would like to make sure my approach is acceptable before submitting a PR.


Solution

  • It's perfectly fine for 3xx or 4xx responses to have body entities, sometimes it's even required.

    For example, for 300 Multiple Choices:

    Unless it was a HEAD request, the response SHOULD include an entity containing a list of resource characteristics and location(s) from which the user or user agent can choose the one most appropriate.