You browse for a product on Amazon, buy it, make a payment and receive a message stating that X amount has been deducted from your account balance. How does this happen? This connection or sync is fulfilled with the help of an API or a Webhook that maintains a link between Amazon and your bank.
So what just happened? Amazon sent a request using an API to your bank to which the latter responded. As simple as it sounds? No? Let us dig deeper.
Now, how do we understand if the service used is an API or a Webhook? For that, let us understand what Webhook and API mean individually.
API is a software intermediary that allows two applications to communicate with each other with a few predefined protocols and definitions in place.
It delivers your request to the provider that you're requesting it from and then delivers the response back to you. Simply put, it acts as a middleman.
Webhook, also commonly referred to as reverse API, web callback or HTTP push API is a medium for an app to provide other applications with real-time information. It delivers data as and when an event occurs.
Application Programming Interface (API) is a software intermediary that allows two applications to communicate with each other. It is a medium by which request-based information and functionality can be shared between two software services.
The requesting app calls the provider app to request specific information and the provider app returns the requested information.
On the other hand, applications that use Webhooks, do not request information. Instead, they are event-based methods that receive updates only when a specific event occurs in the provider app.
Let us establish this with a real-world example:
API can be associated with you calling a store to ask if a product you want to buy is available or not. If it is not available on that particular day, you will again have to follow up on another day to check if it is available because nobody from the store will call you back.
Webhooks, on the other hand, can be correlated to calling a store for a product and giving them your number to be contacted when the product is actually available. In simple words, Webhooks are time-saving for you as well as the other party.
As most of the communications over the internet are carried out through HTTP methods, both Webhook and API use it extensively, the difference being Webhook doesn’t use GET, POST, PUT, DELETE like in case of API.
It only makes an HTTP POST request (which is also known as HTTP callback) to the listener or the service, which asks for an update. In case of Webhook, the listener will be just a simple URL, which it will call with an HTTP POST request for the specific event.
Webhooks are mostly used in cases where a real-time notification or action needs to take place for certain events – slack notifications, continuous integration services and other integrations. Webhooks can be used to exchange data between systems, components within a system or microservices – anything that is attached via the HTTP.