hellomello
hellomello

Reputation: 8585

Ruby on Rails: Capturing JSON data from webhook?

I'm trying to understand how webhook works. My understanding is that its the ability to connect two different applications. If I submit a webhook with url

localhost:3000/receiver

to one application, and I have my application with a method

def receiver

end

I was wondering if I don't know what the callback is from the webhook would be, how would I capture data? How do I save any JSON data thats communicating with my application? I was thinking maybe save some file to see what the objects are, but I'm still fairly new and not sure how to capture JSON data?

Thanks

Upvotes: 3

Views: 2447

Answers (2)

Charizard_
Charizard_

Reputation: 1245

If you are sure that the webhook is returning a JSON, you can so something like this

data_json = JSON.parse request.body.read

Upvotes: 5

rderoldan1
rderoldan1

Reputation: 4078

  1. Sure, a webhook a is tool to sincronize two apps
  2. You HAVE tou know the structure of the incoming json, because you need to get the info inside
  3. By definition a webhook is sent by POST method, so you can capture it just inspecting the body of the petition, i.e.

    webHook = JSON.parse(params[:something])
    

Your would try with github web hooks and publish your app in heroku, the api is very well documented and there are many examples.

Upvotes: 2

Related Questions