Async ReST with a status poll (and how to ultimately get a completed result)

I have a query that is expected to take several hours and I cannot fully determine the ENTIRE stream. I know that this has been discussed several times, including here , but found nothing to answer the questions below (convincingly).

What i know:

  • I will do POST /mysomethings
  • The response will be 202 Acceptedwith a heading Locationthat will contain the full URL where the status can be found (for example, https://api.example.com/statuses/somestatusuuid ).
  • Then the client can poll the status URL and get a response 200 OKwith the response body containing something like{ statusId: someid, status: somestatusstring, description: somestatusdescriptionstring }

To keep things simple and focused, I ignore how authorization will be performed for these requests.

My question is:

What should I do if the resource for the initial request is ready (say, this means that status = "complete").

The best I can come up with is one of the following:

  • In response to the state, an additional key is also included (after state = "full"), for example myresourceId: someuuid, and then the client can makeGET /mysomethings/someuuid

  • The status response (when the resource is ready) will include the Location header with the full URL of the resource (for example, https://api.example.com/mysomethings/someuuid )

  • The combination of both is above, so I have both the resource URL and its id

Some additional thoughts:

  • An IMO would be impractical to return the resource itself in a status request, because the requested information is a status, not an actual resource.

  • I also don’t like the ideas suggested in some places to return 202 for status until the resource is ready, and then returned 201 Created, because status codes should convey the status of the request, not the resource (and definitely not another resource, for which the current request requests only status).

Does all this sound right? Any comments are welcome.
+4
source share
2 answers

What I suggest:

The URL should identify your resource in a simple and unique way. Example:/items/123456

  • GET /items/123456 will return the resource itself
  • POST /items/123456 can load a resource (create or replace)
  • GET /items/123456/status (, JSON)

. GET 404 NOT_FOUND 200 OK .

: GET /items/123456?status, URL- .

0

HTTP 202, , RFC 2616 HTTP 201/202.

, HTTP 200 404, HTTP 202 () HTTP 201 () URI Location ( ).

0

All Articles