Ruby: PUT Request with JSON body?
Using restclient (gem install rest-client) like this:
require 'rubygems'require 'rest_client'require 'json'jdata = JSON.generate(["test"])RestClient.put 'http://localhost:4567/users/123', jdata, {:content_type => :json}
against the following sinatra service:
require 'sinatra'require 'json'put '/users/:id' do |n| data = JSON.parse(request.body.read) "Got #{data} for user #{n}"end
works on my computer.
Easiest way is with Net::HTTP
:
require 'net/http'http = Net::HTTP.new('www.data.com')response = http.request_put('/?access_token=123', jsonbody)