What are WebHooks

   在微信企业号开发中接触到了webhook,所以了解下。

   webhook就是用户通过自定义回调函数的方式来改变Web应用的一种行为,这些回调函数可以由不是该Web应用官方的第三方用户或者开发人员来维护,修改。通过Webhook,你可以自定义一些行为通知到指定的URL去。Webhook的“自定义回调函数”通常是由一些事件触发的,比如推送代码到代码库或者博客下新增一个评论,源站点会为Webhook进行HTTP请求的URI配置。用户通过配置,就可以使一个网站上的事件调用在另一个网站上表现出来,这些事件调用可以是任何事件,但通常应用的是系统集成和消息通知。

         通俗点就是你提供API给其它网站请求,从而通知你某些事件,主要由于系统集成。下面这篇关于pusher的webhook更为详细介绍了webhook。

This guest post comes from Phil Leggetter, Developer Evangelist for Pusher. Phil has developed and worked with real-time web technologies for over 10 years and has written for Programmable Web in the past.

Pusher has established itself as a leading service for delivering WebSocket messages to connected clients via its simple, RESTfulPusher API. This especially suits application developers working with languages and platforms that struggle to maintain and scale persistent connections. We remove the need to roll a custom solution and work with complex and unfamiliar technologies, and ensure the benefits of a hosted service can be achieved. We've recently added support for WebHooks, which provide a different sort of real-time solution.

For some developers, getting feedback about the users and devices that are connected is critical. An application may want to only send broadcast messages when there are people connected, or perform some task when they do so. We therefore needed to come up with a solution to send real-time notifications to these applications. We decided thatWebHooks are the answer and in this post I'll explain what WebHooks are, why we decided they were the best solution and how they can be used.

What is a WebHook?

WebHooks are an HTTP POST callback request sent to URL of a user's choice in response to some event occurring. They offer simple and effective server to server communication without long running connections. As discussed on theWebHooks wiki they have a number of uses; we're using them to send real-time events.

Why do we need WebHooks?

One of our primary goals of Pusher is simplicity. We provide clear and simple APIs for developers and hide away the complex distributed system handling all the messages and events which occur inside Pusher. The server to client message distribution aspect of our service has been a success but we'd also like to make it simple for developers to consume some of our internal events so that they can build more powerful apps. WebHooks fit the bill perfectly because they offer a fantastically simple and elegant way for servers to send each other notifications.

WebHooks mean an app can receive relevant real-time events that are happening with connected clients in a way that is easily:

  • consumed - all that's required is an HTTP endpoint that can handle a POST request
  • integrated with existing architecture - no additional software or components are required. All you need is a web server, which all web apps already have

What can you do with Pusher WebHooks?

In our first release WebHooks give developers access to two core events:

* When a channel is occupied: at least one user is subscribe to a channel
* When a channel becomes vacant: there are no longer any users subscribed to a channel

Here are a few examples of how these events can be used.

Resource saving

Prior to our WebHooks functionality being available it was possible for event messages to be published by an application server to a channel without knowing if anybody was listening. This would mean that the app is using server resources to make an HTTP request to our REST API to publish messages that don't actually get delivered to anybody. Now it's possible to decide whether or not to publish an event message on a channel based on whether it's occupied or not.

3rd Party Data Source Integration

Integrating DataSift and Pusher
It can also be used when integrating with third party data sources such as Twitter. In ourFiltrand demo (blog post), which uses WebHooks, we use the name of the channel (e.g. 'programmableweb') that has become 'occupied' to identify keywords to search for via the Twitter Streaming API . Only when a channel becomes occupied do we begin our search for that Twitter search term and publish messages to that Pusher channel. When the channel becomes vacant we unsubscribe from that search term and stop publishing data to that channel.

I'm particularly excited about this use case, especially when integrated with rich data services such asDataSift.

A custom presence solution

Our presence functionality has been very popular, but there might be some scenarios where a different solution is required. For example, a single channel being occupied might mean that a user is online. By using WebHooks in conjunction with standard application server functionality the application can easily tell if a user is online with the added benefit of being able to send real-time messages directly to them.

Webhooks are the future

WebSockets offer a fantastic way of achieving bi-directional communication between clients and servers, but for server to server communication HTTP is likely to be here for a long time to come. This is simply because there has been a definite focus on the progression of client technologies and we are going to have to wait for the majority of server infrastructures and solutions to catch up.

Because WebHooks offer an easy and powerful way for applications and services to integrate with one another, we believe that the trend towards an interconnected and interchangeable set of loosely coupled cloud services, talking to each other via HTTP requests, is set to continue.


url:https://www.programmableweb.com/news/what-are-webhooks-and-how-do-they-enable-real-time-web/2012/01/30

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值