WebHooks

syed shaheer - Oct 20 - - Dev Community

when 2 computer systems want to communicate with each other there are many ways to do it. One way is the client system polls the other system which means it keeps asking the other system if there is new information. imagine if you wanted to know if your friend had sent you a text message but you had to check your phone every minute to see if there was a new message. client keeps making requests at a predefined interval until a certain desirable state or suitable response is achieved. This process is called polling and causes a lot of resources wasted on both the client side and server side.

Another way is you have to maintain an open connection which means the systems stay connected all the time. imagine you had to hold your phone up to your ear all day just because your friend decided to call you. it can be fast but not practical in all solutions.

To resolve these issues webHooks concept was introduced. Before diving into webHook we should know what is event-driven API because webhook follows event-driven architecture.

what is event-driven APS?

Event-driven APIs, refer to a design pattern where an application sends real-time notifications to other applications or services in response to specific events. These events can include actions like data updates, status changes, or triggers that occur within the sending application.

In webHooks, one system tells the other system what URL it should send information to when there is new information available. let's say you have a social media application that allows users to post updates and you want to notify users when there is a new update. Without webhook, you need to continuously pull the server to check if there is any new update.

whenever a client registers a webhookurl with a server it essentially telling that send me the updates to url whenever something relevant happens. server then can use the URL to send HTTP post requests to the client whenever a relevant event occurs. whenever the server sends an HTTP post request to the web URL, it includes data about the event in the request body. This data can be in any format that both the server and client can understand such as JSON and XML. The client can then use this data to update its own state and display new information to the user.

One of the major advantages is they reduce the load on servers by eliminating the need for clients to constantly poll for updates. It allows the server to notify the client application only when new events occur. webhooks are used by many tech companies like GitHub, Slack, Stripe, etc. to power their application.

There are a lot of differences between HTTP/REST and webHooks. HTTP/REST require client to actively poll for updates whereas webhooks enables servers to push updates to client as soon as they become available. webhooks are triggered by specific events while polling is time driven meaning the client has to keep checking the server at regular intervals even if no update is available.

Thank you and hope this information was useful :)

. . . .