WebHooks in 10 Minutes

18
WebHooks no doubt, familiar with web apis, only a minority familiar with webhooks. webhooks are event callbacks over http. the server/app calls your URL. that’s it. something happens on their end, they ping a url you gave them.

description

This is a quick introduction to webhooks I gave at GlueCon 2010. It was also a bit of an ad for a last minute 40 minute talk I was giving immediately after.

Transcript of WebHooks in 10 Minutes

Page 1: WebHooks in 10 Minutes

WebHooks

no doubt, familiar with web apis, only a minority familiar with webhooks.webhooks are event callbacks over http. the server/app calls your URL. that’s it.something happens on their end, they ping a url you gave them.

Page 2: WebHooks in 10 Minutes

sole champion of webhooks since i coined it in 2006.before 2006, about 1 or 2 of these names used the pattern. PayPal IPN for example. since then its exploded, many of these names adopted webhooks either directly/indirectly because of me, or more importantly because its a good idea.

Page 3: WebHooks in 10 Minutes

Not a protocol

surprise! they aren’t a protocol or a standard. and they won’t be.in fact, i’m not sure what i’m doing on this panel -- however! webhooks *are* the coredelivery mechanic of an open protocol you’ve probably have heard of:

Page 4: WebHooks in 10 Minutes

pubsubhubbub has gotten a lot of coverage and adoption. if you don’t know... (describe). it was created by brett slatkin and brad fitzpatrick. brad should be on this panel, not me. can represent pubsubhubbub here, message is about webhooks and why theyre significant. in fact, let me do that quickly here:

Page 5: WebHooks in 10 Minutes

Telephone analogy

telephone system makes a good analogy. calls are requests. caller is client, receiver is server.imagine friend/fam as web services. call to get info, call to tell them info, call to get them to do something (pick up milk). this is our limited current state of web apis. here’s the problem:

Page 6: WebHooks in 10 Minutes

The “callback”

There is no way for these people/services to call you back... to call you up at some point and tell YOU important information.. to tell you they tried to pick up milk, but they were out of 2%.The best you can do is keep calling them. This is polling. In the real-world, its unacceptable.Imagine getting a prescription in your busy day (without callbacks).

Page 7: WebHooks in 10 Minutes

Program

STDIN STDOUT

Program

similarly, imagine unix pipes, without stdout

Page 8: WebHooks in 10 Minutes

Program

STDIN

Program

it doesn’t work. you need the output that’s not just useful in itself, but can be used as the input of other programs.

Page 9: WebHooks in 10 Minutes

Web App

API

today we have regular apis. but they have no way to give us output outside of our requests.

Page 10: WebHooks in 10 Minutes

Web App

API Events

if web apps had webhook event triggers, something changes in the ecosystem that is really disproportionate to the simple idea of webhooks. this greater thing is called the evented web.talking about it at 11:20 in the other room, full of real examples, code, bigger picture, all that.

Page 11: WebHooks in 10 Minutes

When something happens, perform HTTP POST with relevant data to a URL

that the user gives you.

to reiterate, the idea is simple...

Page 12: WebHooks in 10 Minutes

Why HTTP?

in case its not self evident why this type of infrastructure is not done with xmpp for example:-simplest thing-already understood and ubiquitous, webhooks already set precendent-most important (i would not independently evangelize for 4 years without this):

Page 13: WebHooks in 10 Minutes

HTTP is the easiest way to trigger code

thanks to a spec in 1993 called cgi, we not only have the web as an app platform, but httpis essentially rpc. with everything in the cloud, web development being so popular, it’s now the easiest way to get code to run. write a php script or ruby script. put it in the cloud for free, instantly. why code??

Page 14: WebHooks in 10 Minutes

Code can do anything

having arbitrary code run builtin to this pattern means the possibilities are much richer. instead of having a specific protocol and a client implementation that executes the semantics of that protocol, you have an open ended system. code can do anything: make phone calls, order pizza, take advantage of our api ecosystem.

Page 15: WebHooks in 10 Minutes

Event-driven programmingWriting event handlers

if you take a step back you might see that what this is... is event driven programming.writing webhooks are writing event handlers. this is big.

Page 16: WebHooks in 10 Minutes

Event-driven web“Evented Web”

this is the beginning of a whole new era of web development. programmable web 2.0where small pieces can make a big difference because you can easily glue apps together.

Page 17: WebHooks in 10 Minutes

twitter.addEventListener('newfollower', function(event) { var twitterUser = event.follower; var friends = facebook.getFriendsNames();

if (twitterUser['name'] in friends) { twitter.follow(twitterUser); } else if (twitterUser['following'] > 1000 && twitterUser['followers'] < twitterUser['following'] / 2) { twitter.block(twitterUser); }})

Page 18: WebHooks in 10 Minutes

APIs That Make Things HappenWebHooks and the Evented Web

11:20 in Technical 2