Skip to content

Streaming JSON results in real time with HttpClient.GetFromJsonAsAsyncEnumerable doesn't work in the WASM stack #110287

Answered by MihaZupan
NetherGranite asked this question in Q&A
Discussion options

You must be logged in to vote

Ah, the client in this case is running via WebAssembly on the client browser itself, that uses a different networking stack.
There, responses are not streamed by default, and you have to opt back in via SetBrowserResponseStreamingEnabled.

Changing your sample from

var itemStream = HttpClient.GetFromJsonAsAsyncEnumerable<string>("/api/items");

to

var request = new HttpRequestMessage(HttpMethod.Get, "/api/items");
request.SetBrowserResponseStreamingEnabled(true);
using var response = await HttpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
var itemStream = response.Content.ReadFromJsonAsAsyncEnumerable<string>();

gets you the streaming behavior as expected.

There's som…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@NetherGranite
Comment options

@MihaZupan
Comment options

Answer selected by NetherGranite
@NetherGranite
Comment options

Comment options

You must be logged in to vote
1 reply
@NetherGranite
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
arch-wasm WebAssembly architecture
3 participants