API Health Monitoring with Testfully

API Health Monitoring with Testfully



Introduction


API Monitoring is one of the common use cases of Testfully platform and in this article I will go through the process of defining a health check test, run it manually to make sure it works, configure it to run every 5 minutes and be notified when things go wrong via email.

Most deployed APIs come with a status endpoint which responds with the status of the running API. If you don’t have any endpoint yet, you can use https://httpbin.org/anything so without further ado let’s get started by adding our health check test.

Step #1: Adding the Health Check test


  1. Login to your Testfully dashboard and click on “New Test” link in left nav bar.
  2. Leave the “Folder” blank as it’s not mandatory.
  3. Write a title for your test, something that explains the purpose of your test in plain words. For example, “Availability Check of the API”.
  4. Provide a caption for the first step in your test. For example, “Health check endpoint responds with 200 OK”.
  5. Select the correct method for the endpoint under the test, for example: GET.
  6. Enter your endpoint URL. For example: https://httpbin.org/anything.
  7. “Headers” section can be used to add HTTP headers but for our example, we can leave it blank.
  8. “Payload” tab can be used to add request payload and will be enable for methods that support request body. To keep things simple, we leave it blank.
  9. “Validations” tab is the most important part, switch to this tab and select “200 OK” from the “Response Code”.
  10. Click on the “Save” button to add the test.

Below is how I defined my health check test. Yours should be something similar to this one, albeit with different values.

How to add a health check test in Testfully

Congratulations! You added your health check test. The next step is to run it manually.

Step #2: Verify your test by running it


Before letting Testfully run our health check in background, we should make sure it works so let’s go ahead and run it manually.

As you probably know, test cases are executed against environments so if you don’t have an environment in your account please follow the below steps to add an environment.

  1. Click on the “Environments” link in nav bar
  2. Click on the “New Environment” button
  3. Pick a name for your environment. For example, “Staging”.
  4. Click on “Save” to save the new environment.

With the environment out of the way, we’re good to run our health check scenario manually by:

  1. Click on the “All Tests” link in left nav bar.
  2. You should see your health check test here. Click on the little triangle button in last column of that row and pick one of the available environment, then click on “Run”.
  3. Testfully will run your test and takes you to the result page.

Below is screenshots of the above 3 steps:

Step 1: click on the “Run” button.

Open the Test Run UI

Step 2: Run the test case

Run a test

Step 3: Result Page

Explore test result

Congratulations. We just ran our test and it works! Let’s take to the next step and run it every 5 minutes.

Step #3: API Monitoring


Now that we got a working health check test in place, we need to configure Testfully to run our test in background every 5 minutes and let us know as soon as the test fails. To achieve this, we need to create a collection, add our test to the suite and add automation to the collection. The good news is that with just a few clicks we can do all of the above so:

  • Click on the “New Collection” in left navbar.
  • Pick a title for your collection, for example: “Health Checks”.
  • Under scenarios section, find your health check test and enable toggle it on.
  • Under Automations section
    • Pick one of the available environments.
    • Select “5 minutes” as execution interval in “Runs Every” combo box.
    • Leave “Start At”, “End At” and “Timezone” blank as we want to run the health check straight away and indefinitely.
  • Under Alerts section
    • Pick a value for the frequency of alerts. I would go with Notify once every 15 minutes
    • Pick the mediums for alerts. I picked “Email” by toggling it.
  • Click on the “Save” Button to save the scenario.
  • Click on the “All Collections” in left nav bar, you should be able to see the new “Health Checks” suite.
  • Click on the “Past Runs” icon (last icon) to see a list of previous executions of the “Health Checks” suite.

The below screenshot is how I completed the collection form.

Add a new collection

The new suite showed up in “All Collections” section.

A list of collections

I clicked on “Past Runs” and can see I have already one passed test.

Explore past runs of a collection

Congratulations! Your collection and automation are configured. Testfully continues to run your collection every 5 minutes till you either delete or disable the suite.

comments powered by Disqus

Recent Articles

blog-image
7 HTTP methods and how to use them

HTTP protocol works by clients sending requests to the servers and servers responding to the requests. We do CRUD operations (Create, Read, Update, Delete) by sending HTTP requests with different HTTP methods, sometimes called HTTP verbs.



blog-image
Introduction to API Blueprint

API blueprint is a powerful high-level API design language for web APIs. In this article, we want to dive deeper into it and learn more about how it works, the differences between API blueprint and Swagger, and what makes it unique that leads to its extensive use. But before we dig into API Blueprint, we must ensure a solid base of information about the “API first approach” concepts.

blog-image
False positive & false negative in software testing

Exports in automated software testing have borrowed false positive and false negative terms from the medical examination field. In the medical field, the purpose of a test is to determine whether the patient has a particular medical condition or not. As far as software testing is concerned, a false positive indicates a bug when there is none. Conversely, a false negative indicates no bug when there is one.