Ruby send JSON request

httprequest, json, ruby

Solution

uri = URI('https://myapp.com/api/v1/resource')
body = { param1: 'some value', param2: 'some other value' }
headers = { 'Content-Type': 'application/json' }
response = Net::HTTP.post(uri, body.to_json, headers)

Problem

How do I send a JSON request in ruby? I have a JSON object but I dont think I can just do `.send`. Do I have to have javascript send the form? Or can I use the net/http class in ruby? With header - content type = json and body the json object?

Original source