Sequential params are no longer JSON objects?

15 views
Skip to first unread message

Ethan Pooley

unread,
Mar 24, 2025, 7:02:53 PMMar 24
to KrakenD Community
I am trying to send one JSON object returned by the first backend to the second backend as its body. The information is coming through, but as some kind of internal string representation ("map[name1:value1 name2:value2]") instead of JSON. Are respX params limited to usage as strings, or am I missing something? My config:

{
"endpoint": "/test",
"extra_config": {
"proxy": {
"sequential": true,
"sequential_propagated_params": [ "resp0_headers" ]
}
},
"backend": [
{
"host": [ "https://httpbin.org" ],
"url_pattern": "/get?test=1",
"allow": [ "args", "headers" ]
},
{
"host": [ "https://httpbin.org" ],
"url_pattern": "/post",
"method": "POST",
"allow": [ "data" ],
"extra_config": {
"modifier/lua-backend": {
"allow_open_libs": true,
"pre": "local req = request.load(); req:body(req:params(\"Resp0_headers\"))"
}
}
}
]
}

My result:

Screenshot from 2025-03-24 16-00-09.png

Jorge Tarrero

unread,
Mar 25, 2025, 4:27:57 AMMar 25
to KrakenD Community, Ethan Pooley
Hi Ethan,

Yes, when you specify a response field in the "sequential_propagated_params" you're limited to a single value field, not an object, that's why you're seeing the Golang interpretation of that field (a map structure). 

If you need to propagate several values, either specify them one by one, or switch the backend encoding to "no-op" and propagate the full response with "resp0". The caveat of this second option is that when you retrieve the "req:params('Resp0')" in Lua, it will be a raw JSON string, not a decoded object, so you'll need to decode it first

We have cool helpers in Krakend Enterprise to encode/decode/lookup/transverse... JSON objects. In community edition you'll have to find your own JSON decoder, as Lua does not have native support. This should be a good starting point: https://github.com/rxi/json.lua/blob/master/json.lua 

Cheers,

Reply all
Reply to author
Forward
0 new messages