Skip to main content

JsonStreamRequest

Trait JsonStreamRequest 

Source
pub trait JsonStreamRequest {
    // Required methods
    fn json_array_stream_body<S, T>(self, stream: S) -> RequestBuilder
       where T: Serialize + Send + 'static,
             S: Stream<Item = T> + Send + 'static;
    fn try_json_array_stream_body<S, T, E>(self, stream: S) -> RequestBuilder
       where T: Serialize + Send + 'static,
             S: Stream<Item = Result<T, E>> + Send + 'static,
             E: Into<Box<dyn Error + Send + Sync>> + Send + 'static;
    fn json_nl_stream_body<S, T>(self, stream: S) -> RequestBuilder
       where T: Serialize + Send + 'static,
             S: Stream<Item = T> + Send + 'static;
    fn try_json_nl_stream_body<S, T, E>(self, stream: S) -> RequestBuilder
       where T: Serialize + Send + 'static,
             S: Stream<Item = Result<T, E>> + Send + 'static,
             E: Into<Box<dyn Error + Send + Sync>> + Send + 'static;
}
Available on crate feature json only.
Expand description

Extension trait for reqwest::RequestBuilder that streams a JSON request body.

The try_ variants take a fallible source stream. See ReqwestStreamBody for the HTTP caveats that apply to every streamed request body — the redirect one in particular.

Required Methods§

Source

fn json_array_stream_body<S, T>(self, stream: S) -> RequestBuilder
where T: Serialize + Send + 'static, S: Stream<Item = T> + Send + 'static,

Streams stream as a JSON array, setting Content-Type: application/json.

use futures::stream;
use reqwest_streams::JsonStreamRequest as _;
use serde::Serialize;

#[derive(Serialize)]
struct MyItem {
    field: String,
}

let items = stream::iter(vec![MyItem { field: "value".into() }]);

reqwest::Client::new()
    .post("http://localhost:8080/ingest")
    .json_array_stream_body(items)
    .send()
    .await?;
Source

fn try_json_array_stream_body<S, T, E>(self, stream: S) -> RequestBuilder
where T: Serialize + Send + 'static, S: Stream<Item = Result<T, E>> + Send + 'static, E: Into<Box<dyn Error + Send + Sync>> + Send + 'static,

Streams a fallible stream as a JSON array.

Source

fn json_nl_stream_body<S, T>(self, stream: S) -> RequestBuilder
where T: Serialize + Send + 'static, S: Stream<Item = T> + Send + 'static,

Streams stream as JSON Lines, setting Content-Type: application/jsonstream.

Source

fn try_json_nl_stream_body<S, T, E>(self, stream: S) -> RequestBuilder
where T: Serialize + Send + 'static, S: Stream<Item = Result<T, E>> + Send + 'static, E: Into<Box<dyn Error + Send + Sync>> + Send + 'static,

Streams a fallible stream as JSON Lines.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl JsonStreamRequest for RequestBuilder

Source§

fn json_array_stream_body<S, T>(self, stream: S) -> RequestBuilder
where T: Serialize + Send + 'static, S: Stream<Item = T> + Send + 'static,

Source§

fn try_json_array_stream_body<S, T, E>(self, stream: S) -> RequestBuilder
where T: Serialize + Send + 'static, S: Stream<Item = Result<T, E>> + Send + 'static, E: Into<Box<dyn Error + Send + Sync>> + Send + 'static,

Source§

fn json_nl_stream_body<S, T>(self, stream: S) -> RequestBuilder
where T: Serialize + Send + 'static, S: Stream<Item = T> + Send + 'static,

Source§

fn try_json_nl_stream_body<S, T, E>(self, stream: S) -> RequestBuilder
where T: Serialize + Send + 'static, S: Stream<Item = Result<T, E>> + Send + 'static, E: Into<Box<dyn Error + Send + Sync>> + Send + 'static,

Implementors§