Streaming Responses
Streaming responses are supported in both calling external APIs, and setting up your Xano APIs to deliver streaming responses.
Calling an External Streaming API
You can use the Streaming External API Request endpoint to call an API that returns a stream in almost exactly the same way as you call normal APIs from your function stacks. The only difference is the structure of data returned, which would typically be an array of items that you would leverage a For Each loop to work with.
Streaming Xano API Responses
When delivering certain types of API responses, you may want to 'stream' this response (similar to your favorite AI-powered chatbots). In Xano, this is possible with a simple combination of a For Each loop and a Streaming API Response function.
We'll be using a poem in the public domain to demonstrate the streaming response. You can copy the sample below and use it in your own function stacks to test.
Data that you use for a streaming response needs to be separated into logical pieces. In this example, each item in the array is a new line in the poem. It would typically make the most sense to build a streaming response against an array just for ease of implementation.
Setting up a streaming response
You can now test your streaming API, and should see each item in the array streamed as part of the response.
Please note that your front-end must support streaming responses. If it does not, the response can still be delivered traditionally.
Using Run & Debug will not display a stream, and only the entire response once the stream has completed.
Testing your Streaming Response
Testing in Postman
Create a new request with type HTTP
Paste your API endpoint URL in the URL input, and click Send.
You will see your API response delivered in the result panel.
Testing in Insomnia
Create a new request with type Event Stream
Paste your API endpoint URL in the URL input, and click Connect
You will see your API response delivered in the result panel.
Last updated