This repository contains the CalculatorAPI automation script. Prerequisites:
- DataMiner agent 10.4.6+
- An indexing database
- Postman
- The prerequisites mentioned on the Empower website
- The User-Defined API Calculator API tutorial package from the catalog.
The API script is given to you from the catalog package: ‘CalculatorAPI’. Create an API Definition and an API Token and use Postman to test your API. The URL route should be …/api/custom/calculator/add.
The following exercises will not be done during the Empower session but can be done during your own time. The solutions are included in the package under the solution folder in Automation. The ‘solution’ script contains the API script, the ‘CreateDefinitionAndToken’ script can be executed through cube and will create the definition(s) and token(s) for the exercise.
Open the CalculatorAPI automation script in Visual Studio with DIS and use that to adapt/extend the script. You can use the publish feature in DIS to publish the script to your DataMiner agent.
Our current API can add two numbers together. But we want a new API request ‘calculator/sub’ that can subtract two input numbers from each other.
The difficulty of this exercise is that both APIs, the add and sub API should use the same automation script. Using the ‘ApiTriggerInput’ class, you can differentiate from which route is being used. You should end up with 2 API definitions pointing to the same script.
Our API returns a response based on our request; we therefore only want the GET HTTP method to be used. Change the API script to make sure any request method other than GET gets a 405 status code returned with an appropriate error message.
Instead of using the raw body and splitting it to get the two numbers, change the API script so it expects these to be passed via query parameters. The URL will then have "?a=125&b=250" which would result in 375 when called for the 'add' API.