Home > database >  What http response to notify the client that some elements are missing in the response?
What http response to notify the client that some elements are missing in the response?

Time:07-16

I need to propose a http response for a client's GET. The response must say somehow that some elements in his criteria were not found. Do you have any idea how to do that ? I don't think there is a HTTP response code for it. Should I use the headers ?

CodePudding user response:

You could use a 404 Not Found to say that it is not found and request them to try again.

Alternatively, you could use a 207 Multi-Status and return 2xx for the successful cases and 404 for the ones that were not successful.

It really depends on your use case.

CodePudding user response:

Thanks to Rogue's response, I think the status code 416(Requested Range Not Satisfiable) seems closer to what I'm looking for.

CodePudding user response:

You could implement a custom error response body, in which you can include the detailed message for the client. For example you could have a JSON object as a response where you include the details as follows:

{
    "message": "some elements in your criteria were not found",
    "elements": "A, B, C, D"
}

If you can be more specific about the case and give some details on what exactly are the cases for sending such a response we could help you out with the implementation.

You could assist the response with 400 Bad Request, as the missing details can be related to a bad request.

  • Related