Implementing a client-side WebHook handler?
Asked Answered
P

3

28

I am a bit of a newbie in Webhooks, so excuse me if this is a simple question.

I am clear about how Webhook providers work, i.e. whenever this information needing to be pushed, it sends the payload to the URL specified as callback.

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. 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...

Is there perhaps a JS WebHook Client/Handler that already exists? It seems that this should be so common, that it should exist, although I haven't been able to find anything.

Pleiad answered 6/9, 2012 at 17:2 Comment(0)
S
6

Take a look at 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

Sarmatia answered 6/9, 2012 at 21:12 Comment(1)
do you have anything client side only? I don't want to implement the server side in javascript (I'd rather do that in Python for example), but I want an example of a client side in javascriptOngun
B
3

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).

If you'd like to avoid polling the server for status updates, use WebSockets as matthewhudson pointed out.

Bedraggled answered 24/2, 2021 at 12:31 Comment(0)
D
1

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.

Or you can use any javascript Publisher Subscriber module to easily do this. try googling around for PubSub stuff. here's an example of one such tool: http://www.pubnub.com/tutorial/javascript-push-api

Decolonize answered 6/9, 2012 at 17:10 Comment(5)
Thanks, I had a look at the PubSub tool you suggested, however is it possible to listen to changes from the server-side, or wherever the webhooks is sending data? Or is this only for client-to-client publish/subscribe?Pleiad
Also, how does something like this (i.e. Pubsub frameworks) compare to say "comet" ?Pleiad
comet is a nickname for the act of listening to a data source, so all of the things i mentioned fall under the category of "comet"Decolonize
any time something happens, you need to tell your webhook... post to it. then, separately and simultaneously, you need to ask the webhook what it has and if anything has changed. hence cometDecolonize
How do web page understand anything has changed or received event at client side from server? Any sample example for client end to listen events? thanks!Abash

© 2022 - 2024 — McMap. All rights reserved.