Andrei Visnakovs
Andrei Visnakovs

Reputation: 140

Async resource creation with OData

In REST API if I have a resource which creation could take considerable amount of time I could return a temporary resource with status code 202. Client then could poll this temporary resource until the actual resource is created and get redirected to it when it'd done (with 303 status code). Something like described in http://restcookbook.com/Resources/asynchroneous-operations/.

Is there any standardized way to created such resources in OData?

Upvotes: 2

Views: 549

Answers (1)

GWigWam
GWigWam

Reputation: 2124

Asynchronous requests are (briefly) mentioned in the OData V4 specification. It's probably worth reading for the fine details, but in short:

A client makes a request which includes a Prefer: respond-async header. The server can then respond with a HTTP 202 response as you described. This response includes a Location header which points to the 'status monitor resource'.

When the client sends a request to the status monitor resource there are 3 main responses:

  1. HTTP 202: The operation is not yet completed.
  2. HTTP 200: The operation is completed. This response must also include the AsyncResult header which holds the status code of the operation (e.g. a 200 for success, 5xx for error etc.). The body of this response contains the result of the operation.
  3. HTTP 404:
    • The operation does not exist.
    • The operation was canceled.
    • The operation may have existed, but the client waited too long before requesting the status (May also be HTTP 410 (Gone)).

I don't know of any framework which implements this behavior, so you'll probably have to program it yourself.

Upvotes: 5

Related Questions