Created
January 16, 2019 14:50
-
-
Save ajrussellaudio/58fbbb78586a3e2299dbc450f03b5305 to your computer and use it in GitHub Desktop.
Doing a request in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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