While researching RESTful APIs for asynchronous operations I ran across the following design pattern:
POST uri:longOperation
returns:
- HTTP 202
- Location: uri:pendingOperation
GET uri:pendingOperation
returns:
- If operation is running
- Return a progress report.
- If operation is complete
- HTTP 303
- Location: uri:operationResponse
GET uri:operationResponse
- The response of the asynchronous operation
I find the last step questionable. Consider what happens if the asynchronous operation completes with an error code that doesn't make sense for HTTP GET
, such as HTTP 409 ("Conflict")
.
- Isn't
HTTP 303
required to point to the response associated with uri:pendingOperation as opposed to uri:operationResponse? - Is using
HTTP 303
in this way considered harmful? If not, why? - Is this the best we can do, or is there a better way?