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!
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.
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)?
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!
Join 31,353+ developers who get early access to new screencasts, articles, guides, updates, and more.