3 ms·
Related: anybody have some good examples of a good asynchronous API? This claims to be the standard, but it has confused many of our customers. http://restc
by bryanlarsen 10y ago
Related: anybody have some good examples of a good asynchronous API? This claims to be the standard, but it has confused many of our customers. http://restcookbook.com/Resources/asynchroneous-operations/ http://restcookbook.com/Resources/asynchroneous-operations/
To summarize: send a 202 for the initial request, redirecting to a job URL. The client polls on the job URL, which returns 200 with progress information until it's done, when it returns a 303 redirecting to the final output.
One particular problem spot is that many http libraries automatically follow the 303 redirect, and some even follow the 202 redirect.
I definitely think we would have been better off just putting status and final location information as JSON attributes in the body rather than putting it in HTTP response codes and Location headers. Non-standard, but much less confusing for our customers.
- infinite8s 10y agoIf you have to poll then it's not asynchronous. A better design would utilize something like webhooks.
- bryanlarsen 10y agoYes, we have webhooks, and a grand total of 1 of our customers uses them. Setting up an HTTP server just to receive a webhook is a lot to ask. Long poll lets the polling be efficient.
- bjt 10y ago> If you have to poll then it's not asynchronous. Says who? Maybe not "streaming". Maybe not "real time". But certainly asynchronous.
- kasey_junk 10y agoAll push models are poll models down an abstraction layer.
- infinite8s 10y agoAnd all computations can be modeled as Universal Turing Machines at some level. That doesn't mean it's the most useful level at which to analyze the semantics of what you are trying to accomplish.
- kasey_junk 10y agoSure but saying something isn't asynchronous because its polling is flat wrong.
- retrodict 10y agoDigitalOcean's API does this in quite a few spots [1] - it calls the async jobs "actions", but they signal completion of jobs performed on base objects. [1] https://developers.digitalocean.com/documentation/v2/ https://developers.digitalocean.com/documentation/v2/
- mmalone 10y agoThe short answer is that there is really no good general purpose way to deal with asynchronous communication in a "restful" HTTP API. All solutions have major drawbacks. This is one of the biggest shortfalls of rest/http in my experience. People tend to switch to other protocols to address these use cases (this is a common reason for adopting message bus infrastructure like Kafka as part of a SOA).