Crate reqwest_streams

source ·
Expand description

Streaming responses support for reqwest for different formats:

  • JSON array stream format
  • JSON Lines (NL/NewLines) format
  • CSV stream format
  • 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 allocations to store on the server side.

Example

use reqwest_streams::*;
use futures_util::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(())
}

More and complete examples available on the github in the examples directory.

Need server support?

There is the same functionality:

Modules

Type Aliases