http_json_stream/lib.rs
1//! An asynchronous JSON streamer for HTTP network requests.
2//!
3//! See the [README](https://github.com/LMOORS30/http-json-streamer#http-json-streamer) for additional information, [Installation](https://github.com/LMOORS30/http-json-streamer#cargotoml) and [Features](https://github.com/LMOORS30/http-json-streamer#features).
4//!
5//! [![github-com]](https://github.com/LMOORS30/http-json-streamer)<br>[![crates-io]](https://crates.io/crates/http-json-streamer)<br>[![docs-rs]](crate)
6//!
7//! [github-com]: https://img.shields.io/badge/github.com-LMOORS30/http--json--streamer-5e728a?labelColor=505050&style=for-the-badge&logo=github
8//! [crates-io]: https://img.shields.io/badge/crates.io-http--json--streamer-5e888a?labelColor=505050&style=for-the-badge&logo=rust
9//! [docs-rs]: https://img.shields.io/badge/docs.rs-http--json--streamer-5e8a76?labelColor=505050&style=for-the-badge&logo=docs.rs
10//!
11//! # Example
12//! ```
13//! use futures_util::stream::{StreamExt, TryStreamExt};
14//! use http_json_stream::{JsonPart, JsonStream};
15//! use serde::de::DeserializeOwned;
16//! use std::fmt::Debug;
17//!
18//! async fn log_json_list<T: Debug + DeserializeOwned>(url: &str) {
19//! let fut = Box::pin(reqwest::get(url));
20//! // expected JSON response: '[{}, {}, {}]'
21//! let mut stream = JsonStream::<_, _, T>::request(fut, JsonPart::level(1));
22//! while let Some(item) = stream.try_next().await.unwrap() {
23//! println!("{:?}", item);
24//! }
25//! }
26//!
27//! async fn log_error_response<T>(resp: reqwest::Response) {
28//! if resp.status().is_client_error() {
29//! // expected JSON response: '{ "errors": [{}, {}, {}] }'
30//! let mut stream = JsonStream::process(resp, JsonPart::level(2).group(0));
31//! while let Some(item) = stream.next().await {
32//! let item: serde_json::Value = item.unwrap();
33//! println!("{:?}", item);
34//! }
35//! }
36//! }
37//! ```
38//! <br>
39//!
40//! See [`JsonStream`] and [`JsonPart`] for more information.
41
42mod body_decoder;
43mod error;
44mod json_stream;
45mod partial_json;
46
47pub use body_decoder::{BodyDecoder, ContentEncoding};
48pub use error::{Error, Result};
49pub use json_stream::JsonStream;
50pub use partial_json::{JsonPart, PartialJson};