3

I have number of APIs which is not being hosted by me, so I have no control of the API itself. What I'm trying to achieve is to check whether the APIs is online or not.I already tried several way:

  1. Sent a HTTP request to the API endpoint with HEAD method
  2. Sent a blank HttpWebRequest

    HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
    {
        if (response.StatusCode == HttpStatusCode.NotFound)
            return false;
    
        return true;
    }
    
  3. Ping the server

But somehow my end result is not accurate enough. It shows offline but when I manually try to invoke the API, it seems okay. Anybody got a solution?

3 Answers 3

0

The first option should be good as long as the server can respond to a HEAD request. If it doesn't there should be some safe GET endpoint which can be used instead.

It also makes sense to time the health check so that if the API server is not alive, it won't freeze your app.

0

You can use Postman Monitors to achieve this. Postman offers 1000 free monitor runs on the free account and notifications via email on failures. You can set it up to run on a schedule by specifying the hour/day/week that the monitor should run at.

  1. Simply create a postman collection: https://learning.getpostman.com/docs/postman/collections/creating_collections/
  2. Add your HTTP Health check request in the collection.
  3. Create a monitor on the collection: https://learning.getpostman.com/docs/postman/monitors/setting_up_monitor/
  4. And set up the frequency that it should run with.

You can also manually trigger monitors via the Postman API: https://docs.api.getpostman.com

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.