0

Can someone point me to good resource for Net::HTTP? I'm trying to understand why certain code functions the way it does. For example:

def url_check(domain)
  parsed = URI.parse(domain).host
  check = Net::HTTP.new(parsed).head('/').kind_of? Net::HTTPOK
  ( check == true ? "up" : "down" )
end

I understand 95% of the above code, but I can't find any resources that explain what .head('/') is doing. I'm hoping someone can point me to a good resource that is beginner friendly.

D. Simpson
  • 1,882
  • 17
  • 32
  • 1
    @MitchWheat I so wanted to grump over your simple response. Then I went to the site and found the stdlib subdomain which, of course, contains the reference for every command in existence. I've been there before, but being reminded of it in this manner was a good reminder for me to do a little more fishing **before** I go asking for a fish. – D. Simpson May 14 '11 at 04:14
  • Np. I'm no expert in this area, but I figured I knew where to look! – Mitch Wheat May 14 '11 at 04:16
  • http://apidock.com/ruby/Net/HTTP – lsdr Oct 12 '11 at 04:31

1 Answers1

2

HEAD is an HTTP command that returns just the http headers. head("/") probably just returns the http headers sent by the server in response to request uri "/", ie the root of the website. It is commonly used to do a quick check to see if the page and/or site exists without fetching the entire html page.

You probably also need to learn something about HTTP protocol as well.

GET, POST, HEAD, SET, PUT, DELETE, TRACE are some common ones that come to my head right now there are couple more. You will have better understanding of the code once you understand the basics of HTTP.

d-live
  • 7,926
  • 3
  • 22
  • 16