Skip to content

Instantly share code, notes, and snippets.

@ajrussellaudio
Created January 16, 2019 14:50
Show Gist options
  • Save ajrussellaudio/58fbbb78586a3e2299dbc450f03b5305 to your computer and use it in GitHub Desktop.
Save ajrussellaudio/58fbbb78586a3e2299dbc450f03b5305 to your computer and use it in GitHub Desktop.
Doing a request in Ruby
require 'net/http'
require 'json'
uri = URI('https://restcountries.eu/rest/v2/name/united')
req = Net::HTTP::Get.new uri.path
res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
http.request(req)
end
countries = JSON.parse(res.body)
country_names = countries.map { |country| country['name'] }
puts country_names
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment