Automatically test your REST API

You will learn from this guide how to set up effective monitoring to test your APIs and ensure that they remain functional at all times. Note that the process described below is similar to the one used to monitor a website.

Thanks to this monitoring, in the event that your PLC's response does not correspond to that expected, our robots can perform two types of actions:

  1. Alert the support team of the problem by providing an initial technical analysis
  2. Run a Webhook developed by you that will perform automatic actions such as restarting, displaying a message, quarantining...

  • Summary

Prerequisites

In this guide, we will take as an example a fictitious REST API to allow user authentication. The technical characteristics useful for monitoring are as follows:

  • URL : https://example.hitflow.net/connexion
  • HTTP method used: POST
  • Header "Authorization"": parameter to authenticate the request and authorize the use of the API.
  • The POST parameters to be sent are:
    • username : username of an account dedicated to tests.
    • password : password of the account dedicated to the tests.

When the connection to the user account is successful, the API returns a JSON object with an attribute named "token". Otherwise, this attribute does not exist and the API will return an HTTP 403 code.

Note: To limit the impact of tests on your architecture, you may consider adding an additional parameter to determine if the request is made by a test robot. In the case of our example, this setting could disable the recording of the connection history in the database, which is not the main feature to be tested.

Check the status of your REST API

To start, you must log into your account and then click on "Availability" in the "Monitoring" section of the drop-down menu.

  1. From the list of services you are monitoring, click on the Add button to open a data entry form.
  2. Enter a nameto describe this test. For example: "Connection API"
  3. The type of service to select is HTTPS via the drop-down menu.
  4. Set the verification frequency to the value that suits you best.
  5. Check the "Verification in case of unavailability" box to force the robots to check every minute in case of a problem, until recovery.
  6. Copy and paste the URL of your API into the "Domain name" text field to automatically fill in the domain name, protocol, connection port and path to the API in the various fields provided.
  7. Define the query header by clicking on the "Add" button to display two text fields. In the first text field, enter "Authorization" and then, in the second, enter the authentication token.
  8. The type of request to choose using the drop-down menu is POST.
  9. Add the query data by double-clicking on the "Add" button. On the first line, add the word "username" followed by the user name then on the second line, enter "password" followed by the login password.
  10. Go to the "List of words to be in the page" section and click on the "Add" button. In the text field that has just appeared, add the word "token" and confirm with the enter key.
  11. Modify the list of HTTP error codes to add custom codes that your API can possibly return in the event of an error.
  12. Select from the liste list the contacts who will receive alerts when the API encounters problems.

Save the configuration by clicking on the Save button and then activate the monitoring with the Enable button . You should see the first tests appear after a few minutes in the report page of your test.

Monitoring your server

By following the previous steps, you have seen how to set up the monitoring of a REST API. We invite you to repeat the operation to control all your APIs.

In addition to this monitoring, controlling the use of server resources will also help you to ensure access to the various tools available to your users.