Expand description
An asynchronous JSON streamer for HTTP network requests.
See the README for additional information, Installation and Features.
§Example
use futures_util::stream::{StreamExt, TryStreamExt};
use http_json_stream::{JsonPart, JsonStream};
use serde::de::DeserializeOwned;
use std::fmt::Debug;
async fn log_json_list<T: Debug + DeserializeOwned>(url: &str) {
let fut = Box::pin(reqwest::get(url));
// expected JSON response: '[{}, {}, {}]'
let mut stream = JsonStream::<_, _, T>::request(fut, JsonPart::level(1));
while let Some(item) = stream.try_next().await.unwrap() {
println!("{:?}", item);
}
}
async fn log_error_response<T>(resp: reqwest::Response) {
if resp.status().is_client_error() {
// expected JSON response: '{ "errors": [{}, {}, {}] }'
let mut stream = JsonStream::process(resp, JsonPart::level(2).group(0));
while let Some(item) = stream.next().await {
let item: serde_json::Value = item.unwrap();
println!("{:?}", item);
}
}
}
See JsonStream
and JsonPart
for more information.
Structs§
- Json
Part - A filter for
PartialJson
to determine which items to deserialize. - Json
Stream - An asynchronous JSON streamer for HTTP network requests.
- Partial
Json - A
Write
orExtend
interface to pushJSON
data.
Enums§
- Body
Decoder - A streaming decoder that abstracts over supported content encodings.
- Content
Encoding - Supported HTTP Content-Encoding headers.
- Error
- Errors which can occur while streaming an HTTP JSON response.
Type Aliases§
- Result
- Type alias for the
http_json_stream::Error
result.