Simone
Simone

Reputation: 1337

REST API return code when the service refuses to execute a request

I'm developing a REST API that represents a task manager. It receives requests by "users" who want a task executed, but occasionally the service may reject the request. The request is well-formed (user is authenticated and authorized, the request message can be understood by the task manager, etc.), so no 4xx error: it is the task manager that, maybe because of excessive load or congestion, or because of its inability to manage that request, refuses to execute the request. Still, it may be able to execute it at a later time.

I could respond to the request with a JSON object that includes a "Request accepted" boolean, but I feel that 200 is the wrong status code to return. I should probably return another status code, which should be eloquent enough about the request being accepted or rejected. What status code should I use?

Upvotes: 1

Views: 1132

Answers (1)

Bart
Bart

Reputation: 504

You could use 202 ACCEPTED if your API accepts the request but doesn't immediately executes it. This is not completely your case if I understand it correctly?

503 SERVICE UNAVAILABLE is probably more appropriate as the service refuses to respond to the request.

503 SERVICE UNAVAILABLE 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.

Upvotes: 2

Related Questions