What is Webhook [turn]

I. Overview

Webhook API is a concept, and becoming increasingly popular. The more things we can describe the event, the greater the scope of webhook. Webhook as a lightweight event-processing applications, is becoming increasingly useful.

Accurate to say webhoo is a web callback or http the push API, it is a way to provide real-time information to the APP or other applications. Webhook immediately send data when the data is generated, that is, you can receive data in real time. Unlike typical of this kind of API, the need to use real-time polling needs to be fast enough. This is either for production or the consumer is efficient, the only drawback is the initial setup difficulties.

Webhook sometimes called reverse API, because he provides an API rules, you need to design API to use. Webhook will launch your application http requests, typically post request, the application is driven by the request.

Second, the use webhook

Webhook a consumer is ready to webhook a URL, send a request for webhook. These are usually done by the back pages and or API. This means that your application to set up a URL that can be accessed by the public.

Most webhook released data in two data formats: JSON or XML, which requires explanation. Another data format is application / x-www-form-urlencoded or multipart / form-data. Both methods are easy to resolve, and the majority of Web application framework can do this part of the work.

Three, Webhook debugging

Debugging webhook sometimes very complicated, because webhook principle is asynchronous. The first thing you want to send him the solution, then wait, then check whether there is a response. This is quite tedious and inefficient. Fortunately, there are other ways:

1, webhook understand what can provide, such as the use request collection webhook RequestBin a tool;

2, or with cURL Postman simulated request;

3, test your code using such tools ngrok;

4, with Runscope tool to view the entire process.

Four, webhook security

Because webhook URL to send data to the public on the application, which is to find the URL to others and the chance of erroneous data transmission. You may adopt the technical means to prevent such a thing happen. The easiest way is to use https (TLS connection). In addition to using https, the following method may also be employed to further improve security:

1, the first increase Token, most of the webhook support;

2, an increase of certification;

3, data signing.

Five important questions

There are two things to keep in mind when webhook as consumers:

1, webhook by requesting to send data back to your application, it no longer pays attention to these data. This means that if your application problems, data will be lost. Many webhook will respond to treatment, an error occurs if the program will retransmit the data. If your application is still processing the request and return an error, your application will receive duplicate data.

2, webhook will issue a large number of requests, this will cause your application blocking. Make sure your application can handle these requests.

 

Webhook vs API: What’s the Difference Between Them?

As you become familiar with SendGrid’s services, or even those of many Internet companies, you’ll see the term “API” used a lot. Increasingly, you may also see someone mention a “webhook.”

At SendGrid, we’ve consciously made a distinction between the two in our documentation and any time we write or speak about our seven services for simplifying email. Here’s how we break down the differences between webhooks and APIs.

What is an API?

API stands for Application Programming Interface, but what does that really mean? Rather than what it is, I find it easier to talk about what APIs enable. APIs can share data or functionality. For example, you might use a places API to look up restaurants by location or name, pulling out a lot of data about each place. Then you might combine that with a mapping API, using it as an interface for displaying your data.

Programmers who make a request to an API will then receive a response. For example, using our 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.

What is a Webhook?

Sometimes people call webhooks reverse APIs, but perhaps more accurately a webhook lets you skip a step. 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.

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.

“Call Me When He’s Warmed Up”

Baseball managers could really use webhooks. As the game progresses, they often want to change pitchers. To do this requires the new pitcher to first warm up in the bullpen, which is usually over 300 feet from the team’s dugout. If you watch baseball on television, you’ll often see the manager pick up a phone in the dugout. He’s making a call to the bullpen to check on the new pitcher.

  • “Is he warmed up yet?”
  • “Not yet”

Then he hangs up the phone. In a few minutes he’ll have to call again. Programmers would call this polling and it’s process-intensive for both sides. A webhook lets you say, “call me when he’s warmed up.”

Example Webhooks

SendGrid has two distinct webhooks related to each direction that email flows:

  1. Event Webhook provides data about the emails you send, such as bounces and when the recipient clicks a link.
  2. Inbound Parse Webhook allows your application to receive email as soon as a message comes in.

Some non-SendGrid webhooks:

Hopefully that gives you a few ideas about what a webhook is and how it is different from an API.

Now it’s time to start doing something with those webhooks. Here are four things you can do with webhooks, including testing them on your local machine or connecting them to other services.

Guess you like

Origin www.cnblogs.com/61007257Steven/p/11237439.html