0

I am creating a RESTful API that allows a client to check if a specific service is running at the moment. EDIT: The request address will look something like this - /services/123/running

The possible return values are:

  1. OK (HTTP 200)- the service exists and is running
  2. Not Running (HTTP ???) - the service exists, but it is not running
  3. Not Found (HTTP 404) - the service doesn't exist

What HTTP status code should be used to inform the client that the service does exist, but it is not running at the moment?

EDIT: After more research I found a stackoverflow discussion that somewhat touches on the same topic – What is the appropriate HTTP status code response for a general unsuccessful request (not an error)?

Community
  • 1
  • 1

1 Answers1

1

You do not want to use HTTP status codes for this. They are to indicate how the request went.

Instead you should pass the status in the body of the response. If the request (checking the status of a service) went ok, then the HTTP status code should always be 200, the only thing that differs should be the body.

Examples:

the service exists and is running

Status code 200 Ok
Body {"status": "exists and running"}

the service exists, but it is not running

Status code 200 Ok
Body {"status": "exists, not running"}

the service doesn't exist

Status code 200 Ok
Body {"status": "doesn't exist"}
Tim
  • 41,901
  • 18
  • 127
  • 145
  • This indeed is one way to solve this issue! On the same time it seems to be a topic of much argument - whether to report errors inside REST answers inside HTTP 200 or to use the HTTP status codes :) – Marko Puusaar Jul 01 '15 at 11:45
  • An error code gives you a clear indication of what is going on. You wouldn't want to be parsing the status string to find out the same. It's acceptable if you are just spitting out the message to the user but if you wanted to pragmatically perform an action then it's not a good way to go. The REST client may assume that the request performed successfully when in fact nothing has happened because the service isn't running/doesn't exist. – Liam Jul 01 '15 at 13:06
  • @Liam a service in this case should not be confused with the actual api that is handling the requests – Tim Jul 01 '15 at 13:11
  • I may have described the situation in a little bit cofusing way, but @TimCastelijns got the point right – the REST service is used to inform clients about services available to them (described in a database) and whether a specific service is available/running at the moment. – Marko Puusaar Jul 01 '15 at 13:16