Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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/

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.



If you have to poll then it's not asynchronous. A better design would utilize something like webhooks.


> If you have to poll then it's not asynchronous.

Says who?

Maybe not "streaming". Maybe not "real time". But certainly asynchronous.


Yes, 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.


All push models are poll models down an abstraction layer.


And 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.


Sure but saying something isn't asynchronous because its polling is flat wrong.


The 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).


DigitalOcean'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/




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: