问题
I encounter the following case: I have an API that allows me to retrieve a unique resource:
GET myapi/resource_id
If this resource does not exist, I return a 404
HTTP status code.
This API also allows to retrieve several resources via the same request:
GET myapi/resource_id1,resource_id2
Which HTTP status code should I send back if one of the two resources does not exist?
200 with an explanation in the JSON in an error key
206 which allows to be more explicit with an explanation in the JSON in an error key
400 / 404 code but this is not fine because the API still returns one of the two information
another solution?
Thank you for your help.
回答1:
I think there are 2 options here.
- Send back 200 and don't even mention the missing resource.
- Send back 404 with an empty body.
The 206 is for range requests, the 400 is for malformed requests, so none of those apply here.
来源:https://stackoverflow.com/questions/54673720/rest-api-http-status-for-a-partial-response