Library provides HTTP response streaming support for axum web framework: - JSON array stream format - JSON lines stream format - CSV stream - Protobuf len-prefixed stream format
This type of responses are useful when you are reading huge stream of objects from some source (such as database, file, etc) and want to avoid huge memory allocation.
Cargo.toml:
toml
[dependencies]
axum-streams = { version = "0.5", features=["json", "csv", "protobuf"] }
Example code: ```rust
struct MyTestStructure { sometestfield: String }
fn sourceteststream() -> BoxStream<'static, MyTestStructure> { // Simulating a stream with a plain vector and throttling to show how it works Box::pin(stream::iter(vec![ MyTestStructure { sometestfield: "test1".tostring() }; 1000 ]).throttle(std::time::Duration::frommillis(50))) }
async fn testjsonarraystream() -> impl IntoResponse { StreamBodyWith::jsonarray(sourceteststream()) }
async fn testjsonnlstream() -> impl IntoResponse { StreamBodyWith::jsonnl(sourceteststream()) }
async fn testcsvstream() -> impl IntoResponse { StreamBodyWith::csv(sourceteststream()) }
```
All examples available at examples directory.
To run example use: ```
```
There is the same functionality for: - reqwest-streams.
Apache Software License (ASL)
Abdulla Abdurakhmanov