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?
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?
This works on ruby 2.4 HTTPS Post with JSON object and the response body written out.
A simple json POST request example for those that need it even simpler than what Tom is linking to:
real life example, notify Airbrake API about new deployment via NetHttps
Notes:
in case you doing authentication via Authorisation header set header
req['Authorization'] = "Token xxxxxxxxxxxx"
or http://api.rubyonrails.org/classes/ActionController/HttpAuthentication/Token.htmlThe net/http api can be tough to use.