Skip to content
Tony Arcieri edited this page Feb 14, 2016 · 16 revisions

Require the gem in your project:

require 'http'

And make a GET request:

>> response = HTTP.get('https://www.google.com')
=> #<HTTP/1.0 200 OK @headers={"Content-Type"=>"text/html; charset=UTF-8", "Date"=>"Fri, ...>

We now have a HTTP::Response object for the given request. We can obtain the body by calling #to_s on it:

>> response.to_s
=> "<html><head><meta http-equiv=\"content-type\" content=..."

Or get the response status code by calling #code:

>> response.code
=> 200

Clone this wiki locally