Thomas
Thomas

Reputation: 12107

What http status to return if a service is missing in order to return data

I have a REST service 'A' that relies on an external service 'B' to perform a task.

If 'B' is not available at the time 'A' needs it to fulfill a request, what status should I return?

Is a 503 appropriate in this case? In a way we could say that service 'A' is not available since it can't perform all the work, however in reality only the dependent service is not available.

Upvotes: 0

Views: 506

Answers (1)

cassiomolin
cassiomolin

Reputation: 130957

From the API consumer perspective, it won't mater whether your server or the upstream server that you are proxying is unavailable. You could return either 500 or 503:

6.6.1. 500 Internal Server Error

The 500 (Internal Server Error) status code indicates that the server encountered an unexpected condition that prevented it from fulfilling the request.

6.6.4. 503 Service Unavailable

The 503 (Service Unavailable) status code indicates that the server is currently unable to handle the request due to a temporary overload or scheduled maintenance, which will likely be alleviated after some delay. The server MAY send a Retry-After header field to suggest an appropriate amount of time for the client to wait before retrying the request. [...]

If the operation is read-only, for example, you may want to return some cached/default data to avoid the error.

Upvotes: 1

Related Questions