Assigning a method name in a variable

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)
1 Like

thanks man it helped me lot

1 Like