简体   繁体   中英

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

如果您确定webhook正在返回JSON,那么您可以这样做

data_json = JSON.parse request.body.read
  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, ie

     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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM