Page which responds with 204




















Sending No Content in this case will be better than a or response. How are we doing? Please help us improve Stack Overflow. Take our short survey. Stack Overflow for Teams — Collaborate and share knowledge with a private group.

Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 9 years, 1 month ago. Active 12 months ago. Viewed k times. Improve this question. PatrickMSM Chertes 50 1 1 silver badge 9 9 bronze badges. There is a pretty good article about status code, please find it using following link: blog.

Add a comment. Active Oldest Votes. Improve this answer. Community Bot 1 1 1 silver badge. Satevis Satevis 1, 8 8 silver badges 9 9 bronze badges. Steve Mitchell Steve Mitchell 1, 13 13 silver badges 11 11 bronze badges.

I just wanted to say that your example is beautifully concise. When designing APIs, choosing HTTP status codes is not always that obvious and prone to errors, I hope this post series will help you to avoid common mistakes and choose an adapted one according to the context. To do so, a usual if not standard design pattern is to add query parameters to provide search filters.

The question we will answer today basically is: which HTTP status code respond with when returning an empty list. The No Content status code indicates that the server has successfully fulfilled the request and that there is no additional content to send in the response payload body. While OK being a valid and the most common answer, returning a No Content could make sense as there is absolutely nothing to return. But it can be used on a GET too. If the request is valid, has been successfully fulfilled and if there is no additional content to send which is the case as the returned list would be empty , No Content is perfectly understandable and valid answer.

Though a consumer must be able to interpret any 2xx as as success and fallback to treat it as OK , that means there will be no response body, so no empty list.

A OK with an empty list can be treated the same as non empty list without thinking about it. Note that, consumer may obviously have to check il the list is empty or not to possibly show a message to end user, but the exact same code will work without that control. Apple Safari rejects any such data. Google Chrome and Microsoft Edge discard up to four invalid bytes preceding a valid response.

Firefox tolerates in excess of a kilobyte of invalid data preceding a valid response.



0コメント

  • 1000 / 1000