Sobes.tech
Middle

What is the difference between callback and webhook?

sobes.tech AI

Answer from AI

Callback and webhook are mechanisms for asynchronous interaction between systems, but they differ in implementation and context of use.

  • Callback is a function or method that is passed as an argument to another function and is called after a certain action is completed. Usually, a callback is used within a single application or between components when it is necessary to process the result of an operation.

  • Webhook is an HTTP notification that one system sends to another at a pre-defined URL when a specific event occurs. Webhook operates over the network and allows systems to interact in real-time without constant polling.

Example:

  • Callback: in JavaScript, you pass a function that will execute after data is loaded.
  • Webhook: a payment service sends a POST request to your server when a payment is confirmed.

Thus, a callback is a programming technique within an application, while a webhook is an external notification mechanism via HTTP.