Ask A Question

Notifications

You’re not receiving notifications from this thread.

How to send Webhook?

Andre Zimpel asked in Rails

I'm building a content management service which needs to send a webhook everytime the user saves a record.

What's a best practice to send webhooks in a rails app? A LOT of tutorials are about receiving them but none of them covers sending one. I hope somebody can help me out!

Thank you!

Reply

The cool part about webhooks is that they're just HTTP requests. All you have to do is collect a URL from your user, and then make a POST request to it with some data. I would recommend using rest-client for making the POST and sending it from a background job so that you can retry it if it fails. That's really all their is to it.

You ideally want to schedule your retries for extended periods of time, so if the first one fails, retry in a minute, retry in 5 minutes, retry in 10 minutes, 30 minutes, or something like that where there is some backoff. And then after X number of tries you can give up.

Reply

Btw, definitely doing a screencast on this soon.

Reply

Thank you for your reply!

Ouuuhhh that would be so nice!

One last question: I'd like to keep track of the webhooks. Like a separate site that displays all past (and active) hooks which are saved in a database with a fail count and maybe a response. How would I keep track of the response (just talking about fail or success)?

Reply

That's relatively easy. You can just save a record for every attempt and create/update those according to the number of attempts and they display them on that page. Just need to record the results of the background job after it succeeds or fails and that should be it!

Reply

+1 for a webcast on sending webhooks.

Reply

Another +1 for a video on sending webhooks.

Reply

+1

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,329+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.