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.
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.