11

Programmers who make a request to an API will then receive a response. For example, using Web API to send an email, you’d pass the email contents with the request. If all goes well, you will receive a response declaring success.

To use a webhook, you register a URL with the company providing the service. That URL is a place within your application that will accept the data and do something with it. In some cases, you can tell the provider the situations when you’d like to receive data. Whenever there’s something new, the webhook will send it to your URL.

So, they are basically doing the same thing.

My question is this: What is the difference between webhook and api?

Not in the terms WEBHOOK IS ____ and API IS ______.

I know what are they. I'm interested in key differences and when to use one, and when to use another.

13

The first and main difference between them is that with most APIs there’s a request followed by a response. No request is required for a webhook, it just sends the data when it’s available.

Simple view:

The API is an interface to your data on example.com. The API is used from your server to the example.com platform and can be used to List, Create, Edit or Delete items.

Webhooks are automated calls from example.com to your server triggered when a specific event happens in example.com. For example, when a task is completed and you want to know about it in real time we'll make a POST request to the URL you have registered for the EVENT.COMPLETED webhook in your example account.

So, in a nutshell: The API is where you tell example.com things and Webhooks is where example.com tell you things.

Looking more in depth:

SaaS is a concept - the idea of Software that exists in the cloud and the client is generally a browser. A SaaS application is defined by the functions it can provide to a user (for example Salesforce provides a database that can be used to store customer information) the functions available are determined by the purpose of the application (ie: CRM, Email Blaster, CMS, etc.).

An API is a way for SaaS applications to be connected with other applications via a common communication method (ReST, SOAP, JSON, etc). An API cannot speak directly to another API. An API can be used by a coded application or middleware that acts as a bridge between two API's and runs the thread of execution. For example - both NetSuite and Salesforce have a SOAP API, but for them to communicate - you'd want to use middleware software that can interact with both systems and be configured to pull new contact records through Salesforce's API and push new records to NetSuite through it's API every hour.

Webhooks is another communication protocol for SaaS applications that allows for communication between applications, but simply using HTTP POSTS to control the thread of execution. Webhooks allow an application to speak directly to one another, without using middleware. For example - when you submit a form to WuFoo, it can be set up to initiate an webhooks HTTP POST to another service and pass over some field values from the form submission. Webhooks can also be used in conjunction with an API - for example after the webhook notifies the other application something to happened to record id X, that application could use an API to communicate with the service to check the new field values or modify a status of a record.

It is difficult to have an API or webhooks without having a SaaS application. However, you can easily have a SaaS application that doesn't use webhooks or a (public)API. Similarly, depending on the functions of your SaaS application, you may choose to use webhooks OR an API.

9
+50

API is doing stuff when you ask it to, while Webhook does stuff on it's own when certain criteria match.

So, in a nutshell: The API is where you tell us things and Webhooks is where we tell you things.

via http://apidocs.teamwork.com/article/466-whats-the-difference-between-the-api-and-webhooks

Whenever there’s something new, the webhook will send it to your URL.

via https://sendgrid.com/blog/webhook-vs-api-whats-difference/

5

I'll illustrate this with a concrete example: Credit card payments.

When your site wants to charge a credit card, you call an API at your credit card processor. The credit card processor then charges the credit card returns a success or failure status to that API call.

The credit card processor may need some way of updating your site about this transaction later. For example, the transaction may be reversed next week. Your credit card processor could just send you an email about this. Another way of dealing with it is webhooks. You tell your credit card processor a URL on your site that they can hit and send you data. When the transaction is reversed, a credit card processor that supports web hooks will contact your site at the URL you provide and send you data in machine readable format that you can parse and have your web application deal with automatically.

A webhook is a callback mechanism for an API. You basically implement an API for asynchronous callbacks in conjunction with an API that you are calling.

  • "You basically implement an API for asynchronous callbacks..." - shouldn't that be "webhook"? – MrWhite Jan 26 at 9:30
  • 1
    I'm trying to say that a webhook is an API that you implement. You call an API. A webhook is an API that you implement so that they call you. – Stephen Ostermiller Jan 26 at 9:50
2

Here's an example of the difference between webhook and API in layman's term:

Say you ordered something online and the delivery would be today but you're at work so you told your maid get the package once it arrives. The goal is, you have to be notified if the package already arrived. This is what happens in:

Webhook

  • Once the package arrived, your maid will immediately call you to notify you that the package already arrived.

API

  • The packaged already arrived but you still don't know. You then called you're maid to ask if it already arrived, then she says yes.

The difference is in API you need a trigger to fetch data like the call you made, while webhook automatically notifies you once a new data arrives without the need of a trigger.

0

an Api is simply a small application which is used to gain access to certain features or data in any development platform from an already existing platform, for example: you want to use google geo-location service (already existing platform) on your website (developing platform), instead of rebuilding the whole system and getting to setup your own satellite, you use a small Api to access that feature from google.

While Web hook is simply a return or fall-back Url to your website or platform where the response and data you requested using the Api is been sent to and there you collect the information you seek.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.