Skip to content

Instantly share code, notes, and snippets.

View anowak-r7's full-sized avatar

Adam Nowak anowak-r7

  • Rapid7
  • Toronto, ON
View GitHub Profile
@anowak-r7
anowak-r7 / json_response_handling_ruby.rb
Created December 1, 2015 14:53 — forked from PWSdelta/json_response_handling_ruby.rb
Ruby script that uses open-uri to fetch the contents of a JSON endpoint, uses the JSON gem to parse the string into a Ruby array & prints some of the records. This is the foundation for all web API requests, so feel free to use it in the future.
# http://ruby-doc.org/stdlib-2.0.0/libdoc/open-uri/rdoc/OpenURI.html
require 'open-uri'
# https://github.com/flori/json
require 'json'
# http://stackoverflow.com/questions/9008847/what-is-difference-between-p-and-pp
require 'pp'
# Construct the URL we'll be calling
request_uri = 'http://localhost:3000/users.json'
request_query = ''