❔ streaming an IAsyncEnumerable<string> from complex type
hey. i have a minimal api that looks like this:
it's registered like this:
but whenever i visit the url, the answer is not being streamed but rather returend as one large string. i tried making a dummy endpoint that works like expected, but im unsure how to modify the above code so it works. this is the test that worked for me:
6 Replies
You have misconception about IAsyncEnumerable and it's role in asp.net core. Returning IAsynEnumerable from endpoint doesn't make it stream the data to the client, but rather stream to the json serializer that will serialize it and return it to a client
If you're interested in streaming - http is not the right thing to do that
You can take a look at websockets and especially SignalR
Use streaming in ASP.NET Core SignalR
Learn how to stream data between the client and the server.
ahh gotcha. how come it works like i expected in my second example?
i considered doing it with signalr, but since my simple example worked i thought i could get away without setting it up
I give a test run to your second example, and aparently it works, which honestly wasn't was I expected
It sends results in chunks, but still it's not proper streaming, since connection is closed afterwards
My guess you you just see a string is because delay is too short
If you change
Task.Delay
to lik 10ms, you won't notice anythingokay, i'll spin up a signalr hub and get it working that way. thanks 🙂
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.