Communicating with Other Sites

OK, finally lets zoom back to WebHooks. As we mentioned in earlier videos, nearly every website and service on the internet has ways to communicate with other sites. While REST is common, you can only ‘pull’ data over REST, which makes it high-traffic when you’re constantly polling for new data. Webhooks are how REST-API supporting sites support data ‘pushing’. For example, say you wanted to get a user’s latest Twitter message. Instead of constantly connecting to the twitter API every minute to check if a new message has been posted,  you can ask Twitter to update a webhook URL on each post. That means Twitter will contact you when there’s new data. But, as you can imagine, you need a webserver to listen for that posting. In this case, Adafruit IO can act as that webhook destination.

Adafruit IO only supports receiving data at this time, we need a service that will publish data into a feed. 

Once you have the raw webhook, we need to publish data to it. Once data is published to the raw webhook, it'll appear on the Adafruit IO Feed.

One of the big benefits of webhooks is when you have services that don’t update that often, but you want quick updates when they do. Also, most web services require an API key or authentication - which can be annoying to manage. Webhooks are often ‘free’ with services - so they can easily provide that glue to let you integrate Adafruit IO with other sites with little fuss.

Now, click WebHook to create a URL for data to feed into. Now, if you happen to have control over the webhook publication data to get it into the right format, you can get the data to publish values directly to a feed. That’s fairly complex though. It’s easier to have the webhook be a raw-data destination, where we’ll get the full JSON publication. Once you have the raw webhook, we need to publish data to it.

 

Lets use github.com, which has extensive webhook support. In your account, go to Settings and then Webhook. Lets set up a webhook that will publish to our URL, make sure its posting json data, and we can customize what will trigger the webhook. In this case, let’s have it go off when someone stars one of the Adafruit repositories. Save it and check the feed, you’ll see a new message arrived, that’s their way of testing. Now we can star some repositories, and see new entries come in immediately - way faster than trying to poll github.

One of the big benefits of webhooks is when you have services that don’t update that often, but you want quick updates when they do. Also, most web services require an API key or authentication - which can be annoying to manage. Webhooks are often ‘free’ with services - so they can easily provide that glue to let you integrate Adafruit IO with other sites with little fuss.

This guide was first published on Mar 14, 2019. It was last updated on Mar 14, 2019.

This page (WebHooks) was last updated on Nov 06, 2020.