should http status codes be used in REST API design -
one of advantages of http rest on soap illustration rest utilizes machine language/convention convey lot of meaning (ie http post
means create, http delete
means remove.. etc).. removes lot of ambiguity , room error that's associated free protocols soap..
that said, wondering if it's desirable extend concept http response types.. when comes errors.. lets got api call, want number of available drivers around me:
get api/drivers
if restaurants found.. u'd homecoming json number of restaurants + details etc.. happens when 0 restaurants found? should homecoming info in same format 0? or should utilize http response codes , homecoming http 404 code?
although using 404 code consistent thought of convention on configuration.. , letting machine language of interpretation/explanation.. found engineers complain 404 response more exception beingness thrown, , it's if went wrong, when normal have 0 drivers available in vicinity of user.
update:
in case of finding amount of nearby drivers/restaurants etc.. reply obvious.. happens when you're creating rest api makes assumption.. illustration one
get api/drivers/eta
which means eta of nearest driver.. happens there no drivers around? create more sense utilize 404 here or homecoming normal 200 , explain in json body no drivers exist?
a get
request collection resource can homecoming empty collection. response 200 ok
since (empty) collection exists. returning 404 not found
mean no collection exists not case.
request:
get /restaurants
response:
200 ok content-type: application/json { "count": 0, "restaurants": [] }
api http rest soap
No comments:
Post a Comment