Restlet Client helps you test your APIs by validating responses using assertions. Based on your feedback, we’ve added new powerful operators that allow you to express more (and write less!)
If you want to know more about testing within Restlet Client please refer to our brand-new dedicated documentation.
Matching strings with Regular Expressions
Regular expressions can be considered as the swiss knife of validation and are now available within Restlet Client!
Checking that your response’s status code is in the success range is now as simple as:
Tip: using a sandbox app like Regex101 can be helpful to understand complex regular expressions.
A new Length operation has been designed for Headers and JSON bodies. It is now easy to check that a JSON array returned by the API has a given number of items.
When applied to JSON bodies the Length operator checks:
- The number of characters in a string
- The number of items in an array
- The number of keys in an object
Since headers can also be multivalued, the Length operator will count the number of values provided. The number of values for a header is defined:
- By setting multiple times a header with the same name and different value
- By having a comma separated value
Both cases are supported by the new Length operator.
Checking existence of elements
The Contains operator already exists in Restlet Client but its behaviour evolved to make it more powerful and let you write more advanced assertions. Previously Contains was simply performing a string-based comparison between the expected and actual values. The behaviour is now specific to the value you want to assert on.
When applied to JSON body Contains is defined as follow:
- Strings: standard string comparison
- Arrays: checks that the expected elements are present in the actual array (order does not matter)
- Objects: checks that the expected elements exists as keys in the actual object
Since headers can be multivalued (cf. previous paragraph) the Contains operator is defined as follow:
- If the header has multiple values (multiple entries or comma separated values) then Contains will check that all the expected values are included in the actual values.
- Otherwise a standard string-based comparison will be done between the expected value and the actual one.
Head to our dedicated documentation for more information regarding assertions.