Skip to content

Instantly share code, notes, and snippets.

@madhikarma
Last active January 22, 2017 14:42
Show Gist options
  • Save madhikarma/68d2e80ea5194b1ce30e41f93b85c5d6 to your computer and use it in GitHub Desktop.
Save madhikarma/68d2e80ea5194b1ce30e41f93b85c5d6 to your computer and use it in GitHub Desktop.
Ruby HTTP request
# To use save this file, open a terminal at its location and execute `ruby request.rb`
require 'net/http'
require 'json'
url = "https://api.spotify.com/v1/search?type=artist&q=bonobo"
uri = URI(url)
request = Net::HTTP::Get.new(uri)
request["MyCustomHeader"] = "abcde"
Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
response = http.request(request)
puts(response.body)
json = JSON.parse(response.body)
puts(json)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment