Icicle
Icicle

Reputation: 1174

Any Gem that helps to get the http status of the specified URL in Rails

There are number of URLs that I want to test and want to know the HTTP status of each of these URLs without hitting them in browser.

does anyone has idea about the gem, which can help me to find the solution?

Upvotes: 0

Views: 213

Answers (3)

Michael Kohl
Michael Kohl

Reputation: 66837

How about standard Ruby, no extra gems (just require 'net/http'):

Net::HTTP.new('google.com').head('/').code
#=> "301"

If for some reason you want to do more than a head request, replace head with get.

Upvotes: 2

ksol
ksol

Reputation: 12235

I'm pretty sure you could achieve this with standard ruby (Net::HTTP and friends). However there are many gems to handle stuff like that. I have a bias towards Typhoeus.

Example :

Typhoeus::Request.get('http://google.fr').code
=> 301

Upvotes: 1

Mike Campbell
Mike Campbell

Reputation: 7978

use HTTParty:

uri = "http://url.to.inspect"

request = HTTParty.get( uri )
return true if request.code.to_i == 200

Upvotes: 0

Related Questions