Webhook vs. API—what’s the distinction? As you change into aware of SendGrid’s providers, and even these of many Web corporations, you’ll see the time period “API” used lots. More and more, you might also 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 talk about 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? Relatively 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 number 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 Internet API to ship an electronic mail, you’d move the e-mail contents with the request. If all goes effectively, you’ll obtain a response declaring success.
What’s a Webhook?
Typically individuals name webhooks reverse APIs, however maybe extra precisely a webhook permits 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 out there.
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 circumstances, you may inform the supplier the conditions once you’d wish to obtain knowledge. At any time when there’s one thing new, the webhook will ship it to your URL.
“Name Me When He’s Warmed Up”
Baseball managers may actually use webhooks. As the sport progresses, they typically wish 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 crew’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 must name once more. Programmers would name this polling and it’s process-intensive for each side. A webhook permits you to say, “name me when he’s warmed up.”
Examples of Webhooks vs APIs
SendGrid has two distinct webhooks associated to every route that electronic mail flows:
- Occasion Webhook gives knowledge concerning 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 realize all of the variations between a webhook vs API.
Now it’s time to start out doing one thing with these webhooks. Listed here are 4 issues you are able to do with webhooks, together with testing them in your native machine or connecting them to different providers.