webhook 2021-11-11

2021-11-11  本文已影响0人  9_SooHyun

webhook 网络钩子

引入

当你的应用想从其他别的应用获取消息,你有两种方式。
一是总是轮询其他的应用,以期获得是否有某事件发生的消息;
二是在其他应用上配置webhook URL,当其他应用上有相关事件发生时,会主动推送消息到你的应用

There are two ways your apps can communicate with each other to share information: polling and webhooks.

Webhooks are automated messages sent from apps when something happens. They have a message—or payload—and are sent to a unique URL(named webhook URL)—essentially the app's phone number or address which is configured by user. Webhooks are almost always faster than polling, and require less work on your end.

以生活中的例子来看:

They're much like SMS notifications. Say, your bank sends you an SMS when you make a new purchase. You already told the bank your phone number (this is like that you have configured a webhook url to the bank), so they knew where to send the message. They type out "You just spent $10 at NewStore" and send it to your phone number +1-234-567-8900. Something happened at your bank, and you got a message about it. All is well.

webhook

Webhooks are "user-defined HTTP callbacks"

webhook的功能是,就像当你的银行卡余额变动时,手机能直接获得短信推送一样,当一个app上发生了某个事件event时,可以主动推送消息到yourapp上

实现webhook,简单来说需要两步

{
   "time": 
   "msg":
}

不然的话,你的webhook url接受一类参数,他的webhook url接受另一类参数,那webhook provider就没办法统一处理了

The data format of webhook is usually JSON. The request is done as an HTTP POST request.

本文参考:
https://zapier.com/blog/what-are-webhooks/

上一篇下一篇

猜你喜欢

热点阅读