Webhook vs. API—what’s the distinction? As you change into conversant in SendGrid’s providers, and even these of many Web firms, you’ll see the time period “API” used loads. More and more, you may additionally see somebody point out a “webhook.”
At SendGrid, we’ve consciously made a distinction between the 2 in our documentation and any time we write or discuss our seven providers for simplifying electronic mail. Right here’s how we break down the variations between webhooks and APIs.
Webhook vs API
What’s an API?
API stands for Utility Programming Interface, however what does that actually imply? Reasonably than what it’s, I discover it simpler to speak about what APIs allow. APIs can share knowledge or performance. For instance, you may use a locations API to lookup eating places by location or identify, pulling out a variety of knowledge about every place. Then you definitely may mix that with a mapping API, utilizing it as an interface for displaying your knowledge.
Programmers who make a request to an API will then obtain a response. For instance, utilizing our Net API to ship an electronic mail, you’d go the e-mail contents with the request. If all goes nicely, you’ll obtain a response declaring success.
What’s a Webhook?
Typically folks name webhooks reverse APIs, however maybe extra precisely a webhook allows you to skip a step. With most APIs there’s a request adopted by a response. No request is required for a webhook, it simply sends the info when it’s obtainable.
To make use of a webhook, you register a URL with the corporate offering the service. That URL is a spot inside your software that may settle for the info and do one thing with it. In some instances, you possibly can inform the supplier the conditions once you’d wish to obtain knowledge. Each time there’s one thing new, the webhook will ship it to your URL.
“Name Me When He’s Warmed Up”
Baseball managers might actually use webhooks. As the sport progresses, they typically need to change pitchers. To do that requires the brand new pitcher to first heat up within the bullpen, which is often over 300 toes from the staff’s dugout. Should you watch baseball on tv, you’ll typically see the supervisor decide up a cellphone within the dugout. He’s making a name to the bullpen to test on the brand new pitcher.
- “Is he warmed up but?”
- “Not but”
Then he hangs up the cellphone. In a couple of minutes, he’ll should name once more. Programmers would name this polling and it’s process-intensive for each side. A webhook allows you to say, “name me when he’s warmed up.”
Examples of Webhooks vs APIs
SendGrid has two distinct webhooks associated to every path that electronic mail flows:
- Occasion Webhook gives knowledge in regards to the emails you ship, corresponding to bounces and when the recipient clicks a hyperlink.
- Inbound Parse Webhook permits your software to obtain electronic mail as quickly as a message is available in.
Some non-SendGrid webhooks:
Get began with webhooks
Now, you recognize all of the variations between a webhook vs API.
Now it’s time to begin doing one thing with these webhooks. Listed below are 4 issues you are able to do with webhooks, together with testing them in your native machine or connecting them to different providers.