question

Upvotes
Accepted
2 5 4 9

TRTH2.0 async post

If my request is POST with "Prefer":"respond-async", Shall I still check response code 202? Or it is always either 200 or some 4XX code. This is comparing with GET status, you many keep GET until you get 200 code back.

tick-history-rest-api
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
Accepted
9.6k 10 7 7

Hello @jim.yu

The overview steps to process async post request are listed below:
1.send Post request
2.check the response code:
2.1 200 => get the result.
2.2 other code which is not 200 or 202 => get the error.
2.2 202 => means the result is not ready. Then, extract the location URL in the response headers. Next, execute Get command with the location URL to check the status of the Post request till the response code is not 202 which means the Post request is proceeded completely.
- if the response code is 200 => get the result
- Other code => get the error

For more detail of Async, please refer to Async Key Mechanism

Hope this help.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
13.7k 26 8 12

@jim.yu, to complete Pimchaya's response, you might also want to look at the On Demand extraction workflow description in REST API Tutorial 3.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
2 5 4 9

To get token, we use post with async. The tutorial code just checks if the status code is 200 and treats all other codes as an error. I mean in extreme condition, is it possible a 202 code will return and the above steps have to be followed.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

@@jim.yu, I have requested tokens hundreds of times, and never received a 202.

Is it more precise that we get token in sync mode in this case? Or can someone from server side confirm that get token is in deed a synced request even preferred is async. In my question, I stated 'extreme condition' such as requests are piled up on server side.

@jim.yu

According to the Async key mechanism, methods that support asynchronous requests are annotated with the "Org.OData.Capabilities.V1.AsynchronousRequestsSupported" and a value of "true" in the metadata.

The metadata of "RequestToken" does not have the "AsynchronousRequestsSupported" defined, so this method should support only synced request.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.