Cargo tests and formatting security audit

axum streams for Rust

Library provides HTTP response streaming support for Axum web framework: - JSON array stream format - JSON lines stream format - CSV stream

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 allocations to store on the server side.

Quick start

Cargo.toml: toml [dependencies] axum-streams = { version = "0.2", features=["json", "csv"] }

Example code: ```rust

[derive(Debug, Clone, Deserialize, Serialize)]

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 { StreamBodyWithFormat::new(JsonArrayStreamFormat::new(), sourcetest_stream()) }

async fn testjsonnlstream() -> impl IntoResponse { StreamBodyWithFormat::new(JsonNewLineStreamFormat::new(), sourcetest_stream()) }

async fn testcsvstream() -> impl IntoResponse { StreamBodyWithFormat::new(CsvStreamFormat::new( true, // withheader b',' // CSV delimiter ), sourcetest_stream()) }

```

All examples available at examples directory.

To run example use: ```

cargo run --example json-example

```

Licence

Apache Software License (ASL)

Author

Abdulla Abdurakhmanov