I am working on a change to a working API Management endpoint. I needed to send the request body to a backend service for some authentication / validation before calling the backend service.
I used context.Request.Body.As<string>(preserveContent: true)
to get a copy of the original request body.
However, now my <set-body template="liquid">
template fails with the message "Stream was not readable".
The template is responsible for converting the request body, which is XML, to a JSON format, which the backend accepts.
It was my understanding that using preserveContent: true
will allow the liquid template to access the body but it doesn't appear to be the case.
What other options do I have? Can I store the body on a variable and pass it to liquid explicitly? Is it better to just revert to LINQ to XML, where I at least got control of the data?
Edit:
I have since then abandoned using this feature of liquid for a more manual, but reliable approach.