2

So from what I understand about webhooks, I keep looking up "How to create a webhook from my API" but the results keep giving me how to add a webhook (From say GitHub) from different sites. I'm not sure if this is possible but currently, my react native app polls my node js backend for information every minute. Instead, I want my node js backend to detect a change in my database for a specific user, and then send that updated information to my react native app user. Is this possible, does anyone have any guidance or direction, even a link because all the information I find online is not what I want? Are there any third-party apps that could help in this process? What would I need to do exactly?

Roqaia Alrfou
  • 81
  • 3
  • 13
Vikram Khemlani
  • 555
  • 6
  • 17
  • 1
    https://stackoverflow.com/questions/15505286/postgresql-detect-changes-and-call-webservice // Is that what you're looking for? – Nick Oct 14 '19 at 20:19
  • 5
    This wouldn't be done by a web hook. Webhooks are for servers to tell other servers that something has happened by sending HTTP requests to each other on events. To tell a front-end that something has happened you either use a WebSocket or long polling. – zero298 Oct 14 '19 at 20:35
  • @NickLeBlanc I'm not sure if that's what I'm looking for but thank you I'm gonna look into this. My own is a but different because its user specific and I need the back end to return it to a specific user on the front end, not the entire front end. – Vikram Khemlani Oct 14 '19 at 21:12
  • @zero298 Thanks so much for clearing that up. I'm gonna look into both of those – Vikram Khemlani Oct 14 '19 at 21:13

1 Answers1

8

No, you won’t be able to have a webhook call back to the react app. The app runs within a secure browser, on a secure operating system, on a secure network. At least, hopefully, it runs in a secure environment.

Your in-browser app does not run a web server so even if there was a network route to your machine, how would you receive it? You’d need to bind to a network port somehow. Not gonna happen.

Instead, look into WebSockets or HTTP2 Server-Sent Events (SSE). They allow the servers to push data to a frontend web app running in the browser. It’s not technically webhooks, but the same concept.

Roqaia Alrfou
  • 81
  • 3
  • 13
zmcmahon
  • 401
  • 4
  • 9