Processing Upstream Responses

Let's take a look at how responses from upstream systems provided by request/requests or proxy-request actions can be processed further.

The body function provides you with the raw body of an HTTP response. For further processing, it may be necessary to parse the body using functions like json-parse or xml-parse:

"xml": { "url": "…" } },
"json": { "url": "…" } }
<eval out="$upstream-json">json-parse(body('json'))</eval>
<eval out="$upstream-xml">xml-parse(body('xml'))</eval>
<if test="$upstream-json/success"></if>

The $upstream variable gives additional information about upstream responses like the HTTP status and the headers. The following recursive sub-flow demonstrates a general way how to follow a redirect:


<request>{"id": "my-request", "url": {{ $url }}}</request>
<if test="$upstream/my-request/status = 302">
<eval out="$url">$upstream/my-request/headers/location</eval>
<sub-flow src="request.xml"/>

To just pass the upstream response downstream you can use the pass-body action:

<request>{"url": ""}</request>