TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

REST Hooks - Stop the polling madness

201 点作者 qwertzlcoatl超过 11 年前

33 条评论

annnnd超过 11 年前
Am I the only one who has trouble sifting through all this marketing? Even &quot;read more&quot; link leads to an article where half of the text promises what will be covered and another half talks about some subscriptions and how they are managed (they might have been mentioned in the first half, I agree - and I also read text only twice).<p>If someone has a better understanding of how this works, I would appreciate a TL;DR version for programmers (which are probably the target audience?). Thanks!
评论 #6361045 未加载
评论 #6360867 未加载
评论 #6365071 未加载
评论 #6361157 未加载
评论 #6360701 未加载
评论 #6361588 未加载
评论 #6362576 未加载
评论 #6360795 未加载
steveklabnik超过 11 年前
&gt; REST Hooks itself is not a specification, it is a collection of patterns that treat webhooks like subscriptions.<p>Bummer. No matter if you like it or not, a collection of patterns with a name _is_ a specification, just possibly a poorly defined one. See the confusion in this thread. If it were a link to a spec, nobody would be confused.<p>&gt; Skip the pedantic arguments about standards and implementation details<p>This reads to me as &quot;everyone is going to have a slightly incompatible implementation. One library wont be good enough, I&#x27;ll need to write a new one per site that uses this.&quot;<p>Furthermore, what about PubSubHubbub?<p>Finally, polling is great: Ive found few situations where it doesn&#x27;t work well, people just tend to only do the most basic of implementations and blame polling. See <a href="http://roy.gbiv.com/untangled/2008/paper-tigers-and-hidden-dragons" rel="nofollow">http:&#x2F;&#x2F;roy.gbiv.com&#x2F;untangled&#x2F;2008&#x2F;paper-tigers-and-hidden-d...</a> for a really interesting example.<p>EDIT: numbers were real, added a supporting link
评论 #6361555 未加载
评论 #6361078 未加载
tkellogg超过 11 年前
This isn&#x27;t impressive. [MQTT][1] is a much better protocol, and an open standard. It&#x27;s a pub&#x2F;sub that runs over TCP with variants that run over UDP &amp; TLS. There&#x27;s only a 2+ byte overhead, so it&#x27;s very light. It&#x27;s ideal for mobile devices because it has a QoS system built-in, so the developer doesn&#x27;t have to think through the problem of missing messages where cell service is sub-optimal. MQTT is even resource-based, so it fits well with REST. I wish more people would start using MQTT instead of these crazy hacks like REST Hooks.<p>[1]: <a href="http://mqtt.org/" rel="nofollow">http:&#x2F;&#x2F;mqtt.org&#x2F;</a>
bialecki超过 11 年前
If for some reason you can&#x27;t or don&#x27;t want to implement webhooks, at least make sure you the GET endpoint for any object has a query param that supports fetching the most recently updated or created objects <i>and</i> supports pagination.<p>It sounds trivial, but you&#x27;d be surprised how many APIs don&#x27;t support one or both of those features. When you&#x27;re writing an API it might seem unnecessary to start (after all, who could ever have 1000s of &lt;object&gt;?), but if someone ends up polling your API frequently, having those two features can reduce a lot of unnecessary load for both you and the poller. And, of course, make sure you have an index on the created and&#x2F;or updated dimensions.<p>That said, webhooks are terrific. Few things to consider when implementing them:<p>- Think carefully about the payload you send to the webhook. It&#x27;s usually a good idea to send some related objects&#x2F;data because many times when someone gets a webhook payload, that&#x27;ll trigger calls to your API to get related information you could&#x27;ve reasonably sent them in the initial payload.<p>- You&#x27;ll likely want to some way to keep track of errors so if an endpoint starts returning 404s or 500s you have a way to programmatically discard it after X failed attempts.<p>- In your docs, give sample, &quot;real world&quot; payloads developers can test against. It saves times over creating a RequestBin, pushing there, copying, cURLing, etc. (Remember, you can&#x27;t set up a webhook to localhost.)<p>- A nice to have is some sort of retry capability with an exponential back-off. Servers go offline and if they get pushed webhook data then, those messages are lost. You could say, &quot;tough, it&#x27;s the consumer&#x27;s responsibility,&quot; but if having all the data is important, most people will resort to polling. (Somewhat related, you&#x27;d be surprised how often the APIs of some larger SaaS companies are &quot;offline&quot; -- e.g. returning 503 --, so these things do happen.)
评论 #6364101 未加载
aeon10超过 11 年前
It is awfully difficult to get a technical TL;DR version from a website, whose target audience is programmers. I think explaining what this does concisely and technically, preferably on the front page with code examples etc would be really useful.
bryanh超过 11 年前
We also wrote a quick drop-in Django application [0] (that plugs right into TastyPie if you have an API built on it) . We also have a sample CRM with a live API running [1]. Our friends at NetEngine wrote a sample Rails app [2], and our very own James wrote an awesome Node.js Sails app [3].<p>[0] <a href="https://github.com/zapier/django-rest-hooks" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;zapier&#x2F;django-rest-hooks</a><p>[1] <a href="http://demo.resthooks.org/" rel="nofollow">http:&#x2F;&#x2F;demo.resthooks.org&#x2F;</a><p>[2] <a href="https://github.com/net-engine/resthooks" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;net-engine&#x2F;resthooks</a><p>[3] <a href="https://github.com/zapier/node-resthooksdemo" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;zapier&#x2F;node-resthooksdemo</a>
评论 #6361112 未加载
mikeknoop超过 11 年前
Oh neat! We&#x27;re launching resthooks.org today with several partners to promote an existing but underused real-time API pattern.<p>Here are more resources:<p>Intro: <a href="https://zapier.com/engineering/introducing-resthooksorg/" rel="nofollow">https:&#x2F;&#x2F;zapier.com&#x2F;engineering&#x2F;introducing-resthooksorg&#x2F;</a><p>Why: <a href="http://resthooks.org/#why" rel="nofollow">http:&#x2F;&#x2F;resthooks.org&#x2F;#why</a><p>Demo: <a href="http://demo.resthooks.org/" rel="nofollow">http:&#x2F;&#x2F;demo.resthooks.org&#x2F;</a>
评论 #6360672 未加载
评论 #6360720 未加载
jalfresi超过 11 年前
I hate to be THAT guy but someone was going to say it so it may as well be me :)<p>This is a collection of patterns, right? Well why not make this really REST and rather than list a bunch of URL templates provide REL types for each of these like so:<p>REL subscriptions-list -&gt; GET subscription-create -&gt; POST subscription-read -&gt; GET subscription-update -&gt; PUT subscription-destroy -&gt; DELETE<p>Now it doesn&#x27;t matter what the URL structure is, I can pull the &lt;link&gt; elements from the page and be TOLD the URL, rather than follow a URL template. That way, this doesnt rely on out of band knowledge i.e this web page and its (poor) description.
评论 #6365404 未加载
rcsorensen超过 11 年前
Has anyone use PubSubHubbub ( <a href="http://en.wikipedia.org/wiki/PubSubHubbub" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;PubSubHubbub</a> ) for this pattern in the past? For straight subscriptions, it&#x27;s always been compelling to think of the use cases being covered by PSHB and RSS.
评论 #6360957 未加载
评论 #6360881 未加载
mcantrell超过 11 年前
This sounds like webhooks, but they have a set payload, so that the server that is sent the webhook just calls the rest endpoint it is given in the payload. Interesting idea, but it does sound like a regular webhook to me. That flow is the same way I use the Stripe webhooks for instance. I use the event id and make a call to Stripe directly, so that I can make sure the event is real.
zrail超过 11 年前
I don&#x27;t really understand what this is. Is this an attempt at a formalization of webhooks + JSON?
评论 #6360687 未加载
评论 #6360684 未加载
评论 #6360694 未加载
评论 #6360765 未加载
bdcravens超过 11 年前
The way the info is presented bugs me. The first &quot;case study&quot; is Zapier. Later, in the &quot;Learn how...&quot; set of links, Zapier is listed as one of many. Look to the footer, and the Github link, and it&#x27;s of course evident it&#x27;s a Zapier project.<p>This project (er hmm, &quot;initiative&quot;) is core to Zapier&#x27;s business. If every service out there had a hook atop their service, it&#x27;d make things a lot easier for Zapier. That&#x27;s cool. What bugs me is the feeling that Zapier&#x27;s branding in the whole thing is less than transparent.<p>It seems that open source projects are getting more and more marketing driven, and the way this &quot;initiative&quot; is packaged is a sign of things to come.
评论 #6365019 未加载
nkoren超过 11 年前
Curious if anybody can answer a question for me. I&#x27;ve recently started building some apps with MeteorJS, and am having loads of fun with it. At first I&#x27;d been a bit suspicious of its magic pixie dust -- seemed too good to be true -- but so far it&#x27;s done everything it promised, and has allowed me to focus on developing the parts of the app I care about. After checking briefly to see that my data syncing was genuinely low-latency and low-bandwith (which under every test I&#x27;ve subjected it to, it appears to be), I&#x27;ve pretty much forgotten about this level of engineering and have focused on bigger-picture stuff.<p>Which brings me to the question: should I care about something like REST Hooks? Is it a mistake to become complacent and assume that the lower-level infrastructure will Just Work? Or can MeteorJS (and presumably other high-level frameworks) be trusted to handle this kind of stuff in a way that makes it safe for me to forget about it?<p>Just curious what the esteemed HN denizens think about this, as I&#x27;m sure there are some strong and reasonably well-informed opinions out there...
评论 #6361214 未加载
prodigal_erik超过 11 年前
The docs talk about &quot;event types&quot; like contact.update which do not exist in HTTP and require knowing the semantics of a particular group of resources. To truly be RESTful, I would want &quot;please notify me of any PUT, PATCH, or DELETE to this list of URLs, or POST creating a URL that matches this pattern.&quot; And if you&#x27;re going to include a copy of the resource (I don&#x27;t know what else a payload would be) you need the media type the subscriber expects as if you were doing content negotiation for a GET request from them. Or maybe the payload could just be the current result of a HEAD request so the subscriber can invalidate their caches, and they can send the appropriate GET request(s) when and if they care to.<p>There should be some standard link relation like &lt;link rel=&quot;subscription&quot;&gt; so clients have some hint that this is available and where to request it.<p>I&#x27;d also want some way to manage the freshness&#x2F;load tradeoff, like &quot;please notify me within one hour but no more than every five minutes&quot;.
hcho超过 11 年前
Doesn&#x27;t this assume that the API will only be used from a module living under a URL?<p>Most REST apis these days seem to be consumed form client side.
评论 #6361165 未加载
donpdonp超过 11 年前
In addition to webhooks, using a websocket connection to listen for streaming updates is a great way to eliminate polling.
评论 #6360849 未加载
retrogradeorbit超过 11 年前
Give a man a hammer, everything looks like a nail. REST has become a bit of a hammer. The reason a lot of RESTful designed software I&#x27;ve seen has such poor performance is because REST is used like a hammer... everywhere! And whole bunch of places it&#x27;s not needed and it&#x27;s not ideal.
jalfresi超过 11 年前
I hate to be THAT guy but someone was going to say it so it may as well be me :)<p>This is a collection of patterns, right? Well why not make this really REST and rather than list a bunch of URL templates provide REL types for each of these like so:<p>REL subscriptions-list
derek1800超过 11 年前
Are there patterns for client side JavaScript to be notified of changes to REST resources? I don&#x27;t believe this particular pattern applies if I understand correctly as it needs a URL to notify.
评论 #6360836 未加载
评论 #6361166 未加载
lvh超过 11 年前
I don&#x27;t agree with this part:<p>&gt; In other words, if everyone implemented REST Hooks, server load for both the sender and receiver could be reduced by 66x.<p>No, the number of requests could be reduced by a factor of 66. I&#x27;m not saying that&#x27;s not impressive, I&#x27;m saying that the polling requests that ended up resulting in no action are cheaper than actionable requests, so, server load will go down by much less than a factor of 66x. The amount of <i>work</i> is the same, just <i>busywork</i> is less.
评论 #6361158 未加载
lojack超过 11 年前
While the paradigm of having a webhook makes more sense, I personally hate working with them. I&#x27;ve yet to see a graceful way of handling local development that doesn&#x27;t involve localtunnel (or some alternative) and constantly having to un-register and re-register endpoints every time localtunnel gives you a new hostname. I understand the point and would prefer working with them if there was just a good way to handle local development.
评论 #6361803 未加载
dpweb超过 11 年前
Powerful idea, should be made a specification. Simple enough too - what they describe is almost trivial to implement in &#x2F;* insert your web framework of choice *&#x2F;. You wouldn&#x27;t even need a library. Handle your HTTP verbs, store subscriber state, and call them out on events. It&#x27;s nice.
tlrobinson超过 11 年前
Here&#x27;s another (work in progress) spec for managing webhook&#x2F;HTTP callback subscriptions: <a href="https://github.com/progrium/http-subscriptions/blob/master/SPEC.md" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;progrium&#x2F;http-subscriptions&#x2F;blob&#x2F;master&#x2F;S...</a>
bdcravens超过 11 年前
Why is this a thing? Your API interfaces with a message queue; your end client uses all the libraries and patterns built up over the years to consume from the queue. That doesn&#x27;t sound all startup-y like &quot;REST Hooks&quot;, but the pattern has been around for a long time.
geuis超过 11 年前
I just want to point out that having read that entire page, I still have absolutely no idea what this is, how it works, etc.<p>I have a solution for polling. Its called websockets. Even more, there&#x27;s a well-supported library called socket.io that transparently handles it for all browsers.
Kiro超过 11 年前
After reading through all the comments here I still can&#x27;t figure out what this is. Sorry.
评论 #6361180 未加载
jedberg超过 11 年前
Isn&#x27;t this like SUP?<p><a href="http://blog.friendfeed.com/2008/08/simple-update-protocol-fetch-updates.html" rel="nofollow">http:&#x2F;&#x2F;blog.friendfeed.com&#x2F;2008&#x2F;08&#x2F;simple-update-protocol-fe...</a>
andreineculau超过 11 年前
FWIW <a href="http://barelyenough.org/blog/2009/05/push-or-pull/" rel="nofollow">http:&#x2F;&#x2F;barelyenough.org&#x2F;blog&#x2F;2009&#x2F;05&#x2F;push-or-pull&#x2F;</a> case closed
Hovertruck超过 11 年前
&gt; On average, 98.5% of polls are wasted<p>Erm. Is there a source for that?
评论 #6360917 未加载
评论 #6360817 未加载
veesahni超过 11 年前
TL;DR - REST Hooks is an API pattern where the API provides an endpoint from which webhooks can be programmatically setup and removed.
derefr超过 11 年前
This sounds pretty much like the polyfill Socket.IO&#x2F;SockJS do to create a socket atop polling-based transports.
bradhe超过 11 年前
I have no idea what this is.
harel超过 11 年前
Someone should show this to Facebook.... Just saying...