Don't call us, we will call you!
Let's go back to days when internet or mobile phones aren't present yet. I've a bank account running, and I like to know updates if amount is credited or debited. Whenever I would like to know, I used to call up bank and ask them.
After a few calls, I noticed I've no updates. The pattern made bank decide to launch a subscription model. They call me if there's any activity in my account, and I don't have to call them.
This is what webhooks do, in internet era. While HTTP Rest api calls are made for user on-demand purposes, webhooks are made to respond to actions and send to system.
My bank account had all the transactions human controlled and the person who controls transactions keeps a track of what to update. Some time in the evening, the human calls up all customers and update about their account activities.
With the advent of computers, we're able to solve the problem effecitvely. Calls got replaced by mails, humans aren't involved anymore in the transactions.
Whenever there's a transaction in my bank account, the webhook gets triggered. The webhook carries all the necessary information such as account number, amount credited, transaction identifier, the time of the transaction and other details.
Using all the details, an email is generated and lands in my inbox. There's also an SMS update with minimal details.
The system scaled up really well and new avenues opened up. Today, webhooks are used in various applications to send out notifications, system updates and trigger other set of actions.
How does a webhook look like?
Webhook is generally a HTTP POST call with JSON/XML transmitted. JSON/XML holds all the necessary data, accepted by the server.
The data is validated by the server. Webhooks are asynchronous by nature. While this is great, it invites backend service processing webhooks to be up always and data to be sent adheres to service's contract.
Any invalid data in webhook or data loss due to backend service failure, is lost forever.
Sounds too fancy, does anyone use it?
Several applications rely on webhooks to trigger notifications, learn more about user and other use cases.
- IFTTT can change your display picture on twitter as soon as you've changed it on Facebook. It acts as a webhook broker between two independent services, and let's the user define interactions.
- Slack consumes webhooks from any source and posts a message to channels based on event configurations. Our server health reporter uses webhook to post data to slack, when there's a change in health.
Can I try out a simple webhook?
Submit your email address below. It uses webhook to send out emails to you later whenever a new post is live on my website. ¯_(ツ)_/¯