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.
The example uses JSON data from a GET request to postman-echo.com
like this:
{
"body": {
"args": {},
"headers": {
"host": "postman-echo.com",
"x-request-start": "t1757972551.591",
"connection": "close",
"x-forwarded-proto": "https",
"x-forwarded-port": "443",
"x-amzn-trace-id": "Root=1-68c88847-aaaaaaaaaaaaaaaaaaaaaaaa",
"user-agent": "PostmanRuntime/7.46.0",
"accept": "*/*",
"cache-control": "no-cache",
"postman-token": "00000000-1111-2222-3333-444444444444",
"accept-encoding": "gzip, deflate, br",
"cookie": "sails.sid=s%3AdummySessionId1234567890.abcdef1234567890"
},
"url": "https://postman-echo.com/get"
},
"http": {
"status": 200,
"headers": {
"Date": "Mon, 15 Sep 2025 21:42:31 GMT",
"Content-Type": "application/json; charset=utf-8",
"Content-Length": "621",
"Connection": "keep-alive",
"Server": "nginx",
"ETag": "W/"26d-FAKEETAG1234567890"",
"Set-Cookie": "sails.sid=s%3AdummySetCookieId0987654321.qwerty9876543210; Path=/; HttpOnly"
}
},
"tests": [],
"binary": false
}
The TypeScript in this condition finds the response’s status code and checks if the code is greater than or equal to 400:
response.http.status >= 400
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.
Number((response.http.headers["Server-Timing"] || "")
.match(/dur=([\d.]+)/)?.[1]) > 1000
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.
!(response.http.headers["Content-Type"]?.includes("application/json"))
To see this TypeScript in an example flow, check out TypeScript example 3: Response health and performance routing.
Last modified: 2025/09/20