Restlet Client recently released a feature called “automatic update of expressions” that helps to maintain expression consistency when requests are moved. Expressions were added to Restlet Client years ago. When you want to reuse the output of one request as an input for another, use an expression; this unleashes the true power of Restlet Client.
Let’s illustrate this new feature and follow Homer Smithson who leads the API development team at McDonut’s, a software editor. McDonut’s develops and maintains a set of APIs in order to connect their products together. As the development team increases in maturity, they move faster and constantly update their APIs. After having suffered from too many regressions, they’ve decided that they really need to start automatically testing their APIs.
Homer’s team’s requirements are simple: run a sequence of requests (known as a “scenario” in Restlet Client), and view the result of each individual request. In many cases, requests are set based on the results of previous ones. For example, when creating a new resource, its URL is returned by the server in a header “Location”, which can be used for further requests.
What’s the problem?
Homer wants to test the “Create Burger” operation on the Burgers API.
- The first step of the scenario is a POST request that creates a new burger whose location is sent back by the server in the “Location” header.
- In a second step, the state of the created resource is checked by sending a GET request to the URL of the created resource. This URL cannot be inferred so we need to get it from the previous request using an expression.
Here is a screenshot of the “Burgers API” scenario and expression.
Once this first scenario is done, Homer moves to the next one called “Donuts API”.
Thanks to conventions, most of the APIs look similar and so will the test scenarios. Hence, Homer plans to copy the first test scenario, rename it, rename requests, and adjust the other details.
Homer rapidly notices that there is an issue with expressions since they were kept unchanged while copying the scenario. They still refer the first scenario, which leads Homer to update all expressions manually.
Let’s automate this!
The task is boring and error-prone but luckily Restlet Client introduced a shiny new setting that you can opt-in for, which when activated will ensure that Restlet Client maintains the consistency of your expressions.
Once the setting is enabled, anytime Homer copies a scenario, the expressions are updated automatically:
When Homer updates the name of the first request from “Create a new burger” to “Create a new donut”, then the expression is also updated:
Et voilà, problem solved!
If you like us and believe that this feature will make your life easier then give it a try and send us your feedback by email or in-app messaging so that the next cool feature is the one you need!