Hey folks,
Is there a simple way to reference http request body in transformRequestBody
middleware?
Goal: transform request with body to put whole incoming request body into one key-value pair of outgoing request.
Incoming request body (key-value pair count may vary):
{
"param1":"value1",
"param2":"value2",
"param3":"value3",
"param_n":"value_n"
}
Desired outcome:
{
"output": {
"param1":"value1",
"param2":"value2",
"param3":"value3",
"param_n":"value_n"
}
}
in my template if I do:
"output": {{ . }} | jsonMarshal
it does the thing, but includes unwanted key-value pairs _tyk_context
&& _tyk_meta
.
If I start playing by creating new object and indexing all key-value pairs but _tyk_context
&& _tyk_meta
I never get a valid JSON output because of extra newlines or whitespaces.
Closest I’ve got with creating new object was this template (but result contains too much newlines to be correctly marshalled as json):
{{ $filtered := dict }}
{{ range $k, $v := . }}
{{ if not (or (eq $k "_tyk_context") (eq $k "_tyk_meta")) }}
{{ $_ := set $filtered $k $v }}
{{ end }}
{{ end }}
{
"output": {{ $filtered | jsonMarshal}}
}
Any advice please?