What’s a Webhook? Or… When Life Give You Lemons
First things first, you might be asking: ‘What the hell is a webhook?’
Simply put, a webhook is a method of initiating or changing a behavior of a web application utilizing custom HTTP POST requests also known as callbacks. “Hooked” yet? No? Ok, let’s expand on that. Picture that you’re in the business of lemonade in 2018. You run a lemonade e-comm business called “Pucker Up,” and you want to provide the highest possible value to your new and returning customers. Picture a user story as follows involving webhooks:
- A user comes to your page and is greeted by your sites built in chatbot who asks what they might be looking for today.
- Your user has interest in the Sour Cherry Lemonade product that you carry, and they ask your chatbot if that product is currently available.
- The chatbot provides the pricing and all relevant product information to the user for the Sour Cherry Lemonade
- The user decides he/she wants that product and asks the chatbot to add it to their cart, which the chatbot does
- The user requests information from the chatbot on a few more items, asks to add all the items to their cart, and asks the chatbot to bring him/her to check out, which the chatbot all does.
How did this all happen? As you can probably guess, with webhooks. Webhooks specialize in setting up specific workflows which are triggered by specific user actions. In this example, our user makes multiple requests to our chatbot, including viewing product information and adding items to their cart. These requests trigger their respective workflows for the chatbot to initiate, and the user receives the proper data or behavior on the client side.
This is merely one example, and webhooks can be utilized in a variety of other ways such as through Stripe who has a variety of webhooks, including one that will automatically send a notification email to a customer who’s subscription payment fails.
Setting Up A Webhook
Setting up a webhook is surprisingly simple, and all that it requires is registering a callback URL with whichever company or service you are requesting data from or initializing a workflow. Facebook Messenger has a surprisingly easy set up to create your own chatbot through their webhook, and their service even allows you to set up or integrate your own custom workflows that can live on your company’s Facebook Page for greater user support or care.
Webhooks vs. API’s
You may have been asking “Why should I use a Webhook? Can’t I simply use an API?”, and the answer is yes, you can! However, there are a few key differences between Webhooks and API’s:
- API’s place calls even when there is potentially not data, while Webhooks sit and wait to be triggered through specific user actions, preventing wasteful API calls.
- Webhooks provide your applications with nearly perfect real-time information. While this is possible through API’s, they involve additional configuration and utilize more resources then webhooks.
- Webhooks can be utilized when the API being called is very poor, or there is no API at all. Workaround solutions to deliver data that your application needs to function can be sent through a webhook!
Get “Hooked In”
Webhooks are being utilized more and more around web development, and are being offered through a variety of services. Stripe and Facebook Messenger were mentioned above, and additional services such as Zapier allow you to link certain apps together that can trigger actions within each other through webhooks. Github utilizes webhooks to update third-party applications about repository updates, and companies like SendGrid use webhooks to automate specific emails through user actions (such as shipping confirmations or password resets).
If you’re beginning to develop a new service or revisiting how your current services are running, you may find that webhooks can make your services smoother than a fresh glass of lemonade.