reqwest-streams

Crates.ioreqwest-streams
lib.rsreqwest-streams
version0.8.1
sourcesrc
created_at2022-07-31 13:40:40.19788
updated_at2024-11-07 16:17:35.588921
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
size119,802
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: 100

cargo fmt