Alexander Smith
Alexander Smith

Reputation: 157

Rails 5.1 - net/http PUT request

New to Rails 5.1 and trying to send a PUT request with net/http and uri, not sure if I am setting the parameters correctly

Need to put ['Authorization'] in the Header

def put_function
  uri = URI.parse('https://api.url.com/venues/' + ENV['VENUE_ID'] + '/request')
  params = { 'email'      => request.email,
             'notes'      => request.comments }

  req = Net::HTTP::Put.new(uri)
  req.body = params
  req.authorization = ENV['AUTH_CODE']

  p req

  data = JSON.parse(req.body)
  p data
end

Upvotes: 1

Views: 1966

Answers (1)

Alexander Smith
Alexander Smith

Reputation: 157

require 'uri'
require 'net/http'

url = URI("https://api.url.com/venues/" + ENV['VENUE_ID'] + "/[email protected]&notes=test")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Put.new(url)
request["authorization"] = ENV['AUTH_CODE']
request["cache-control"] = 'no-cache'

response = http.request(request)
puts response.read_body

Upvotes: 3

Related Questions