There is an exact duplicate of this question that is over four years old here
Given that it's been so long, my question now is, is that answer still accurate? Is there a better way to do this now?
There is an exact duplicate of this question that is over four years old here
Given that it's been so long, my question now is, is that answer still accurate? Is there a better way to do this now?
You do something like this. Write a function in your controller like this:
require 'net/http'
require 'net/https'
class custom_class
def get_api_call(args_hash)
uri = URI.parse("sample_api_url")
uri.query = URI.encode_www_form(what_args_you_want_to_send)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(uri.request_uri)
http.request(request).body
end
private
def what_args_you_want_to_send
{
"varname1" => var1,
"varname2" => var2,
"varname3" => var3,
"varname4" => var4
}
end
The result of that function will have the answer from the server you are send a request to