Original Message:
Sent: Fri August 01, 2025 05:38 AM
From: Mounika Nayikoti
Subject: Format of invoke response body in APIC - Why Buffer instead of JSON?
Hi Steve,
Thank you for your detailed response - it really cleared my doubt about why the invoke
response is stored as a buffer.
Just to confirm, in scenarios where we need to extract specific fields from the response body (for example, fetching a token value from the first invoke
response and sending it in another invoke
call), parsing the buffer to JSON would have a performance impact, correct?
I'm trying to understand whether this cost is negligible for small payloads, or if we should look at alternative extraction approaches to optimize performance.
Thanks again for your guidance!
------------------------------
Mounika Nayikoti
Original Message:
Sent: Thu July 31, 2025 02:29 PM
From: Steve Linn
Subject: Format of invoke response body in APIC - Why Buffer instead of JSON?
Hi Mounika,
The invoke policy will always return a buffer with the exact contents that were on the wire. It is up to the API to decide if it wants/needs the buffer parsed or not. Parsing does impact the whitespace for example which could impact any type of hashing which would be one reason to not parse it. You can use either the parse policy, or in GatewayScript, you'll read the message.body as a buffer and can used JSON.parse(theBuffer) to parse it within your code. If you need the parsed payload for a subsequent policy, the parse policy would be recommended as it would be more performant than the GatewayScript, but if using GatewayScript, you could also do context.set to place the parsed JSON into your body variable.
Regards,
Steve Linn
------------------------------
Steve Linn
Senior Consulting I/T Specialist
IBM Retired
Original Message:
Sent: Thu July 31, 2025 05:58 AM
From: Mounika Nayikoti
Subject: Format of invoke response body in APIC - Why Buffer instead of JSON?
I have a setup where:
I have both a proxy API and a backend API.
The backend API is configured to return Content-Type: application/json
.
The proxy calls the backend API using an invoke
policy.
When I inspect the invoke
response object in the proxy (e.g. context.message.body.write(JSON.stringify(context.get('tokenResponse')));
), the body
property shows as: "body": {"type":"Buffer","data":[123,34,97,99,99,101,115,115,95,116,111,107,101..}" Instead of a parsed JSON object.
My questions:
In what format does APIC store the invoke
response object?
Why is the JSON response represented as a Buffer?
Is using a Parse
policy the only recommended way to convert the buffer to a JSON object, or is there a direct way in GatewayScript?
I want to understand the expected behavior and best practice for handling backend JSON responses in proxy APIs.
Thanks in advance for any guidance!
------------------------------
Mounika Nayikoti
------------------------------