Prerequisites: A StringServlet exists in the station. The httpClient palette is open.
- Double-click the StringServlet and expand Response Body.
The
Response Body properties open.
- To add one or more alternative responses, drag a ConditionalResponse component from the palette to the Response Body folder and double-click the ConditionalResponse component.
The response properties open.
- Enter an alternative
Data property and Response Code.This example links the output of a JSONSchema component to the
Data slot. For this
ConditionalResponse to be used, some conditions must be defined. Several example conditions are available in the palette:
- Expand and drag a condition, such as BodyContains from the palette to the Conditions folder under ConditionalResponse and double-click the condition.
The condition’s properties open.
- Set the
Not value to true.This negates the defined logic.
If you have multiple conditions defined, the default logic requires that all must be true. Set the And slot to false and only one of the conditions needs to be true.
- To configure a response report, enter a filename for
Report Name and define the file extension using the Report File Ext property.These are the last properties at the bottom of the
StringServlet AX Property Sheet.
- To create a file to capture each request in the station home folder, link this topic to an appropriate recipient, such as
a report FileRecipient.
- Right-click the servlet component and click .
In the example, when we repeat the same external request, the conditional response returns:
curl -k -u MrBasic:Manager123 -X POST "https://127.0.0.1/temperature" -d '{"getTemp":"Inside"}'
{"time":1626273698782,"temp":21,"units":"°C"}
It is also possible to send GET requests to a StringServlet. The functionality is the same, except no Request Body can be posted.