#http #web #stream #axus

axum-streams

HTTP body streaming support for Axus: JSON/CSV and others

9 releases (4 breaking)

0.8.1 Feb 4, 2023
0.8.0 Nov 25, 2022
0.7.0 Aug 14, 2022
0.5.0 Jul 31, 2022

#602 in Network programming

Download history 15/week @ 2022-12-01 31/week @ 2022-12-08 11/week @ 2022-12-15 11/week @ 2022-12-22 23/week @ 2022-12-29 14/week @ 2023-01-05 14/week @ 2023-01-12 11/week @ 2023-01-19 14/week @ 2023-01-26 42/week @ 2023-02-02 46/week @ 2023-02-09 53/week @ 2023-02-16 21/week @ 2023-02-23 7/week @ 2023-03-02 27/week @ 2023-03-09 53/week @ 2023-03-16

122 downloads per month
Used in reqwest-streams

Apache-2.0

25KB
500 lines

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
  • 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.

Quick start

Cargo.toml:

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

Compatibility matrix

axum axum-streams
0.6 0.8
0.5 0.7

Example code:


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

fn my_source_stream() -> impl Stream<Item=MyTestStructure> {
  // Simulating a stream with a plain vector and throttling to show how it works
  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 {
  StreamBodyAs::json_array(source_test_stream())
}

async fn test_json_nl_stream() -> impl IntoResponse {
  StreamBodyAs::json_nl(source_test_stream())
}

async fn test_csv_stream() -> impl IntoResponse {
  StreamBodyAs::csv(source_test_stream())
}

All examples available at examples directory.

To run example use:

# cargo run --example json-example --features json

Need client support?

There is the same functionality for:

Licence

Apache Software License (ASL)

Author

Abdulla Abdurakhmanov

Dependencies

~6–12MB
~198K SLoC