
When to use HTTP status code 404 in an API
404 Not Found - The server has not found anything matching the Request-URI. In the context of your API, it very much depends on how queries are created and how objects are retrieved. But, my interpretation has always been that: If I ask for a particular object, and it exists return 200 code, if it doesn't exist return the correct 404 code.
Should I return a 204 or a 404 response when a resource is not …
2016年6月22日 · Instead, you should throw new NotFoundException(); to indicate to the framework that the entry doesn't exist, so that it would generate a HTTP 404. If I should change it to a 404, obvious question: I should change the method signature right? No, you don't. That's the nice thing about throw new NotFoundException();. It will work no matter what ...
What's the proper response when I try to update an existing entity …
2022年11月28日 · For example, a 404 could be used to indicate that there is no entity with the ID {id}. A 403 would indicate that the client doesn't have permission to access or modify the entity with the ID {id}. A 405 can be returned if the entity with ID {id} cannot be modified by the PUT or PATCH request the client sent. A 415 could be returned if the ...
rest - Should we return a HTTP 404 or 400 for a customer record …
2020年4月25日 · The 404 means page/endpoint not found. All 400-499 errors mean the client/caller made some mistakes (in the case of 404 - the client is trying to hit an endpoint which does not exist). If the record is not found then it should simply return 200 with empty data. –
Rest API POST with illegal data in parameters: Bad Request or 404?
2019年7月9日 · The 422 (Unprocessable Entity) status code means the server understands the content type of the request entity (hence a 415(Unsupported Media Type) status code is inappropriate), and the syntax of the request entity is correct (thus a 400 (Bad Request) status code is inappropriate) but was unable to process the contained instructions.
rest - What is a proper response status code to POST when parent ...
2018年1月24日 · 404 NOT FOUND seems to be an appropriate response, because the resource with this ID does not exist. It's very clear to understand and you are expecting the same response if a/{id} is called. 409 CONFLICT does not seem to be the better choice, because in your example you will return a 409 when the parent resource was not found :).
Is a 422 response ever appropriate for a GET request?
2022年3月18日 · Since a GET request isn't going to be processing anything (vs. a POST) it seems like a 404 is more appropriate if a query results in an entity not found. Conversely a 404 would never be appropriate for a POST. But hey maybe I have it wrong and need to be educated.
api design - Should a REST API return a 500 Internal Server Error to ...
2018年3月23日 · HTTP 404 is correct, because the server understands what resource the client is asking for, but it doesn't have that resource. The fact that you're working with a "REST API" is the key. The API should behave like it's performing a REpresentational State …
RESTful API design. What should I return if there are no rows?
The reason I don't suggest returning HTTP 404 in this case is that the bookshelf is still there. There aren't any books on it at the moment, but it is still a bookshelf. If it weren't a bookshelf -if the API didn't intend to collect books, for example- then HTTP 404 would be appropriate. But because there's a resource there, you shouldn't ...
Http Status Code When Downstream Validation Fails
2019年10月21日 · You could also consider 409 Conflict and 422 Unprocessable Entity. The latter has the advantage of highlighting the message-body of the request as the source of the problem. One of the reasons for this can be that the user used an expired card. Fine grained domain-specific semantics belong in the response body.