4 ms·
I like the convention: - 404 if resource requested by id - 200 with empty list of results if it was a 'search' type request with params (not referring directl
by benrow 3y ago
I like the convention:
- 404 if resource requested by id
- 200 with empty list of results if it was a 'search' type request with params (not referring directly to an id)
- tuetuopay 3y agothis is the standard we have company-wide and it works pretty well, unless you make a mistake in the uri (like picking up the wrong api version). however, all apis will return some info on their root, so it's easy to distinguish and troubleshoot
- Banditoz 3y agoWhat about 204? https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/204 https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/204
- benrow 3y agoI still prefer 200 with an empty list for the 'no results' case. The same client code works, rather than having to code for 204. - If I query for an identifier which doesn't exist - Server replies 404, this should fall into my error handling as there's a data inconsistency - If I query say like ?category=automotive&price=1 and I get a 200 containing a json body in which there's an empty list of matches, then my client code can handle 0 matches as well as 1 or 10 with no special handling.