axum-streams 0.1.0

HTTP body streaming support for Axus: JSON/CSV and others
Documentation
axum-streams-0.1.0 has been yanked.

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

Quick start

Cargo.toml:

[dependencies]
axum-streams = { version = "0.1", features=["json", "csv"] }

Example code:


#[derive(Debug, Clone, Deserialize, Serialize)]
struct MyTestStructure {
  some_test_field: String
}

fn source_test_stream() -> BoxStream<'static, MyTestStructure> {
  // Simulating a stream with a plain vector and throttling to show how it works
  Box::pin(stream::iter(vec![
    MyTestStructure {
      some_test_field: "test1".to_string()
    }; 1000
  ]).throttle(std::time::Duration::from_millis(50)))
}

async fn test_json_array_stream() -> impl IntoResponse {
  StreamBodyWithFormat ::new(JsonArrayStreamFormat::new(), source_test_stream())
}

async fn test_json_nl_stream() -> impl IntoResponse {
  StreamBodyWithFormat ::new(JsonNewLineStreamFormat::new(), source_test_stream())
}

async fn test_csv_stream() -> impl IntoResponse {
    StreamBodyWithFormat ::new(CsvStreamFormat::new(
        true, // with_header
        b',' // CSV delimiter
    ), source_test_stream())
}

All examples available at examples directory.

To run example use:

# cargo run --example json-example

Licence

Apache Software License (ASL)

Author

Abdulla Abdurakhmanov