Route response data with TypeScript in Flows
This example uses three TypeScript expressions to route response data based on health and performance using a Condition block. The first expression to return true routes the response data through its output port. If none of the three TypeScript expressions resolve to true, the Condition block routes the response data through the Default output port.
Example JSON
The example uses JSON data from a GET request to postman-echo.com like this:
Condition 1: Check for critical server errors
The TypeScript in this condition finds the response’s status code and checks if the code is greater than or equal to 400:
Condition 2: Check for slow response
The TypeScript in this condition finds the Server-Timing header value and checks if it’s greater than 1000. The Server-Timing header shows the number of milliseconds the request took to process. If it’s greater than 1000 ms, that could indicate a slow response.
Condition 3: Not JSON
The TypeScript in this condition checks if the Content-Type header is missing the string application/json. If application/json isn’t present in the header, the expression returns true and routes the response from this condition’s output port. If the string is present, the expression returns false.
Example
To see this TypeScript in an example flow, check out TypeScript example 3: Response health and performance routing.