Re:Ask HN: What is your go-to example for a good REST API?
by infinite8s on Friday June 24, 2016 @04:12PM
(#11973066)
If you have to poll then it's not asynchronous. A better design would utilize something like webhooks.
Re:Ask HN: What is your go-to example for a good REST API?
by bjt on Friday June 24, 2016 @06:32PM
(#11974006)
> If you have to poll then it's not asynchronous.
Says who?
Maybe not "streaming". Maybe not "real time". But certainly asynchronous.
Re:Ask HN: What is your go-to example for a good REST API?
by bryanlarsen on Friday June 24, 2016 @04:28PM
(#11973202)
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.
Re:Ask HN: What is your go-to example for a good REST API?
by kasey_junk on Friday June 24, 2016 @07:46PM
(#11974384)
All push models are poll models down an abstraction layer.
Re:Ask HN: What is your go-to example for a good REST API?
by infinite8s on Friday June 24, 2016 @08:44PM
(#11974601)
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.
Re:Ask HN: What is your go-to example for a good REST API?
by kasey_junk on Friday June 24, 2016 @09:26PM
(#11974729)
Sure but saying something isn't asynchronous because its polling is flat wrong.
Re:Ask HN: What is your go-to example for a good REST API?
by mmalone on Friday June 24, 2016 @06:49PM
(#11974098)
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).
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.