0

I have a REST webservice that encapsulates multiple external APIs. Let's assume my customers can input a BookingId to my REST webservice. I then pass that id to the external api and return the booking, if possible.

Now, if the bookingid does not exist, the external API response with HTTP 200 and some custom message.

But I'd like to show the correct HTTP statuscode to my clients.

Question: which code would you expect a webservice to return incase you enter eg an invalid/nonexisting bookingid?

Probably one of the 4xx client error codes? As the invalid bookingid was given by the client.

But which one? 400 Bad Request if for invalid query parameters (not values). 404 Not Found is for (static?) resources not available anymore.

membersound
  • 81,582
  • 193
  • 585
  • 1,120
  • Independent if your service is a facade or something like that. A similar question can be found [What's the most appropriate HTTP status code for an “item not found” error page](https://stackoverflow.com/questions/5604816/whats-the-most-appropriate-http-status-code-for-an-item-not-found-error-page) . The answer is: Stick with `404`. – andih Jun 12 '17 at 07:58

1 Answers1

0

A quick overview of the most used HTTP codes

403 : Not Acceptable (useful when for example a parameter is missing)
404 : Not Found
500 : Server Error
200 : OK
201 : Inserted (use it when you put somthing)
418 : I'm a teapot

You can also use some custom codes e.g :

10003 two entries cannot have the same id

Alexi Coard
  • 7,106
  • 12
  • 38
  • 58