Architecture – Web Service and Message Queue

Architectureenterprise-architecturehttp-responsemessage-queueweb services

We're looking at creating a web services/REST API layer that will be consumed by web and mobile clients.

To make the solution more robust I was considering putting the commands from PUT, POST, and PATCH onto a message queue, which would mean that they would then be executed asynchronously.

Is there a standard HTTP response from a RESTful API that indicates that a command will be executed asynchronously?

Edit

Actually, if anyone had any thoughts on how sensible it is to have a message queue behind a web services layer I'd be interested to hear them.

Best Answer

The successful creation of the task to do whatever was successful. This means that one should be looking in the 2xx block of the response codes.

In this block one jumps out as the correct answer quite quickly:

202 Accepted
The request has been accepted for processing, but the processing has not been completed. The request might or might not eventually be acted upon, as it might be disallowed when processing actually takes place.

You may also wish to look at the 201 response for situations where the resource (the task) has been created, and you just want to say that.

201 Created
The request has been fulfilled and resulted in a new resource being created.

This, however does not imply the asynchronous nature of the interaction and instead implies that it is there, somewhere.

Related Topic