reqwest-streams

Crates.ioreqwest-streams
lib.rsreqwest-streams
version0.6.0
sourcesrc
created_at2022-07-31 13:40:40.19788
updated_at2024-07-12 12:19:51.777085
descriptionHTTP body streaming support for reqwest: JSON/CSV/Protobuf and others
homepagehttps://github.com/abdolence/reqwest-streams-rs
repositoryhttps://github.com/abdolence/reqwest-streams-rs
max_upload_size
id636146
size108,873
Abdulla Abdurakhmanov (abdolence)

documentation

https://docs.rs/reqwest-streams

README

Cargo tests and formatting security audit

reqwest streams for Rust

Library provides HTTP response streaming support for reqwest:

  • JSON array stream format
  • JSON lines stream format
  • CSV stream
  • Protobuf len-prefixed stream format
  • Arrow IPC 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]
reqwest-streams = { version = "0.7", features=["json", "csv", "protobuf", "arrow"] }

Example code:


use reqwest_streams::*;
use futures::stream::BoxStream;
use serde::{Deserialize, Serialize};

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

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {

    let _stream = reqwest::get("http://localhost:8080/json-array")
        .await?
        .json_array_stream::<MyTestStructure>(1024);

    Ok(())
}

All examples available in examples directory.

To run example use:

# cargo run --example json-stream

Need server support?

There is the same functionality:

Licence

Apache Software License (ASL)

Author

Abdulla Abdurakhmanov

Commit count: 89

cargo fmt