Assertions

API Check Assertions

What are Assertions?

Assertions are conditions that you set to validate the status code and response time of your API request. They help ensure that your API behaves as expected under various conditions. When one or more assertions fail, an alert is triggered, allowing you to take immediate action.

Types of Assertions

You can set the following types of assertions for your API checks:

  • Response Time: Set a value and check against that value. If the response time exceeds the specified value, the assertion fails, causing the test to fail.
  • Status Code: Specify the expected status code of the API response. If the response code is different from the expected value, the assertion fails, causing the API Check to fail.

Set Assertions

Failed Assertions and Check Details

When an assertion fails, the details of the failure will be visible on the check details page. This includes information about which assertion failed and why, helping you quickly identify and resolve issues.

Interaction with Response Limits

If a check has a response time limit and is marked as degraded but also has a failing assertion, the check will be marked as failed. This ensures that all critical issues are captured and addressed promptly.

How to Set Assertions

  1. Access Assertions Settings: Navigate to the assertions settings for your API Check.
  2. Add Assertions: Specify the type of assertion you want to add (Response Time, Status Code).
  3. Set Criteria: Define the criteria for the assertion (e.g., expected status code, maximum response time).
  4. Save Settings: Make sure to save your settings to apply the assertions.

Practical Use Cases

  • Performance Monitoring: Use response time assertions to ensure your API meets performance benchmarks.
  • Error Detection: Use status code assertions to detect unexpected errors or failures in your API.

By using assertions, you can ensure that your APIs are performing as expected and delivering the correct data, helping maintain the reliability and performance of your services.