one of the advantages of http REST over SOAP for example is that REST utilizes machine language/convention to convey a lot of the meaning (ie an http POST
means create, http DELETE
means remove.. etc).. so it removes a lot of ambiguity and room for error that's associated with free for all protocols like soap..
that said, I was wondering if it's desirable to extend that concept into http response types.. specifically when it comes to errors.. so lets say i got this api call, where I want to get the number of available drivers around me:
get api/drivers
if some drivers are found.. then normally u'd return json with the number of drivers + details etc.. but what happens when 0 drivers are found? should you return the data in the same format with 0? or should you utilize http response codes and return an http 404 code?
although using a 404 code would be consistent with the idea of convention over configuration.. and letting machine language do most of the interpretation/explanation.. i found some engineers who complain that a 404 response is more like an exception being thrown, and it's as if something went wrong, when it is perfectly normal to have 0 drivers available in the vicinity of the user.
update:
in the case of finding amount of nearby drivers/restaurants etc.. the answer is probably obvious.. but what happens when you're creating a rest api that makes an assumption.. for example this one
get api/drivers/eta
which means get the eta of the nearest driver.. what happens where there are no drivers around? would it make more sense to use 404 here or return a normal 200 and explain in the json body that no drivers exist?