Fetch remote JSON in Ruby


/ Published in: Ruby
Save to your folder(s)

An example method for fetching remote JSON data in Ruby.


Copy this code and paste it in your HTML
  1. require 'rubygems'
  2. require 'json'
  3. require 'net/http'
  4.  
  5. def fetch(url)
  6. resp = Net::HTTP.get_response(URI.parse(url))
  7. data = resp.body
  8. JSON.parse(data)
  9. end
  10.  
  11. puts fetch "http://example.org/sample.json"

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.