简体   繁体   English

实现客户端 WebHook 处理程序?

[英]Implementing a client-side WebHook handler?

I am a bit of a newbie in Webhooks, so excuse me if this is a simple question.我是 Webhooks 的新手,所以如果这是一个简单的问题,请原谅我。

I am clear about how Webhook providers work, ie whenever this information needing to be pushed, it sends the payload to the URL specified as callback.我很清楚 Webhook 提供程序的工作方式,即每当需要推送此信息时,它都会将有效负载发送到指定为回调的 URL。

Now my question is: how do I write a client-side Webhook handler, that can detect/process the callback and update my client-side accordingly.现在我的问题是:我如何编写一个客户端 Webhook 处理程序,它可以检测/处理回调并相应地更新我的客户端。 For example, if my client-side is a simple web-page with bullet-points, I would like to append new data to the list, whenever it comes through.例如,如果我的客户端是一个带有项目符号的简单网页,我想在新数据出现时将其附加到列表中。

Preferably, I would be after a complete JavaScript solution...最好,我会追求一个完整的 JavaScript 解决方案......

Is there perhaps a JS WebHook Client/Handler that already exists?是否可能已经存在一个 JS WebHook 客户端/处理程序? It seems that this should be so common, that it should exist, although I haven't been able to find anything.看起来这应该是很常见的,它应该存在,虽然我一直没能找到任何东西。

Take a look at WebSockets.看看 WebSockets。 Depending on your needs, this could be exactly what you need to avoid polling and keep things in sync - particularly if you have a lots of clients who need to see the same updates from your server.根据您的需要,这可能正是您避免轮询和保持同步所需要的 - 特别是如果您有很多客户端需要从您的服务器看到相同的更新。

I highly recommend Socket.IO我强烈推荐Socket.IO

To consume a webhook API endpoint, or in other words, to "listen for changes", you'd poll for changes, long-poll for changes, or anything else clever you'd like to do.要使用 webhook API 端点,或者换句话说,“侦听更改”,您需要轮询更改、长轮询更改或任何其他您想做的聪明的事情。

Or you can use any javascript Publisher Subscriber module to easily do this.或者您可以使用任何 javascript Publisher Subscriber 模块轻松完成此操作。 try googling around for PubSub stuff.尝试在谷歌上搜索 PubSub 的东西。 here's an example of one such tool: http://www.pubnub.com/tutorial/javascript-push-api这是一个此类工具的示例: http : //www.pubnub.com/tutorial/javascript-push-api

web hooks are not made for this.网络钩子不是为此而制作的。 Event notification in web hooks is done through POST requests meaning your client app cannot be notified about new events unless it listens for incoming HTTP requests (usually the client is behind a firewall so this will not be feasible in most cases). Web 钩子中的事件通知是通过 POST 请求完成的,这意味着您的客户端应用程序无法收到有关新事件的通知,除非它侦听传入的 HTTP 请求(通常客户端位于防火墙后面,因此在大多数情况下这是不可行的)。

If you'd like to avoid polling the server for status updates, use WebSockets as matthewhudson pointed out.如果您想避免轮询服务器以获取状态更新,请使用matthewhudson指出的 WebSockets。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在客户端JavaScript中实现Webhook? - Implement Webhook in Client-Side JavaScript? 是否保证在 *after* 客户端智能支付按钮 .then() 之后触发 webhook? - Is it guarranteed that a webhook will be triggered *after* client-side Smart Payment Buttons .then()? 实现客户端图像编辑器 - 最好的方法是什么? - Implementing a client-side image editor - what's the best way? 在现有的Codeigniter hmvc应用程序中实现requirejs和客户端模板 - Implementing requirejs and client-side templating in existing codeigniter hmvc application 从客户端处理程序返回false不会阻止回发 - Returning false from Client-Side Handler does not Prevent Postback 如何发出错误才能在客户端的错误处理程序上捕获它? - How to emit error to be possible catch it on error handler on client-side? 客户端分页 - Client-side pagination 从客户端正则表达式实现服务器端正则表达式验证 - implementing server-side regex validation from client-side regex 如何在RichFaces中同时添加服务器端和客户端事件处理程序 - How to add both server-side and client-side event handler in RichFaces Vue.js:使用vue-router和商店实现客户端的静态路由器 - Vue.js: Implementing client-side restful router with vue-router and a store
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM