How do I return a Stream from a server function? #3210
-
Hello Leptos community! I have a question though: How do I return a Stream from a server function? Allow for a streaming value with #server. But I haven't been able to figure it out. I've tried something like this:
which is supposed to stream an incrementing value to the client every second, but it doesn't compile because of these errors:
I'd appreciate any help. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi eliaxelang007! leptos/examples/server_fns_axum/src/app.rs Line 487 in 8f8f3e2 The available codes are in the docs for the server_fn crate, I think you're looking for this one: https://docs.rs/server_fn/latest/server_fn/codec/struct.ByteStream.html The short of it is to set the output encoding to Streaming, and then return the ByteStream type, much like the example does with TextStream. |
Beta Was this translation helpful? Give feedback.
Hi eliaxelang007!
You'll want to take a look at our server fns example here:
leptos/examples/server_fns_axum/src/app.rs
Line 487 in 8f8f3e2
The available codes are in the docs for the server_fn crate, I think you're looking for this one:
https://docs.rs/server_fn/latest/server_fn/codec/struct.ByteStream.html
The short of it is to set the output encoding to Streaming, and then return the ByteStream type, much like the example does with TextStream.