method_name = “get”
response = HTTP.headers(endpoint_headers).method_name(endpoint_url)
please help me how to make it work
note: i want to achieve this using only http gem
method_name = “get”
response = HTTP.headers(endpoint_headers).method_name(endpoint_url)
please help me how to make it work
note: i want to achieve this using only http gem
If what you want is to consume api, I advise you to use better REST Client – simple DSL for accessing HTTP and REST resources
require 'rest-client'
require 'json'
endpoint_url = 'https://reqres.in/api/users?page=2'
method_name = 'get'
endpoint_headers = { 'Content-Type' => 'application/json' }
response = RestClient::Request.execute(method: method_name,
url: endpoint_url,
headers: endpoint_headers)
result = JSON.parse(response)
puts result
i wanted this solution using HTTP gem
method_name = “get”
response = HTTP.headers(endpoint_headers).send(method_name, endpoint_url)
thanks man it helped me lot
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs