How to cache Web API response?

Is there a web service API where you can pass in a URL and it returns the HTTP response code?

  • Answer:

    You can do this in the language of your choice, rather than having to call a web service (a web service that calls a web service?). Here's an example in Python, using httplib: import httplib def get_http_status(host, path='/'): """Returns the status code of the given host and path by requesting HEAD from the host (there's a joke in there somewhere). In the event of a networking error, an httplib exception will be raised. """ connection = httplib.HTTPConnection(host) connection.request('HEAD', path) return connection.getresponse().status print get_http_status('www.quora.com') # Should print '200' print get_http_status('www.quora.com', '/does/not/exist') # Should print '404' You could write an equivalent in PHP, Ruby, or any language that has some form of HTTP library. If you're looking to do this for debugging purposes, take a look at something like HTTP Client (a nifty Mac application): http://ditchnet.org/httpclient/

Anonymous at Quora Visit the source

Was this solution helpful to you?

Other answers

Depending on the programming language you're using, you could just use a built-in library to fetch the url yourself and parse out the response code (e.g. curl functions in PHP, Net::HTTP in Ruby) I would think calling an external web service for this would overcomplicate the solution.

Kyle Bragger

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.