Accessing the request/response payload when streaming is enabled

In Edge, the default behavior is that HTTP request and response payloads are stored in an in-memory buffer before they are processed by the policies in the API Proxy.

If streaming is enabled, then request and response payloads are streamed without modification to the client app (for responses) and the target endpoint (for requests). Streaming is useful especially if an application accepts or returns large payloads, or if there’s an application that returns data in chunks over time.

Antipattern

Accessing the request/response payload with streaming enabled causes Edge to go back to the default buffering mode.

Figure 1: Accessing request/response payload with streaming enabled

The illustration above shows that we are trying to extract variables from the request payload and converting the JSON response payload to XML using JSONToXML policy. This will disable the streaming in Edge.

Impact

  • Streaming will be disabled which can lead to increased latencies in processing the data
  • Increase in the heap memory usage or OutOfMemory Errors can be observed on Message Processors due to use of in-memory buffers especially if we have large request/response payloads

Best practice

  • Don't access the request/response payload when streaming is enabled.

Further reading