car_mirror_reqwest/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![warn(missing_debug_implementations, missing_docs, rust_2018_idioms)]
3#![deny(unreachable_pub)]
4
5//! # car-mirror-reqwest
6//!
7//! A helper library that helps making car-mirror client requests using reqwest.
8//!
9//! ## Examples
10//!
11//! ```
12//! # use anyhow::Result;
13//! use car_mirror::{cache::NoCache, common::Config};
14//! use car_mirror_reqwest::RequestBuilderExt;
15//! use reqwest::Client;
16//! use wnfs_common::{BlockStore, MemoryBlockStore, CODEC_RAW};
17//!
18//! # #[test_log::test(tokio::main)]
19//! # async fn main() -> Result<()> {
20//! // Say, you have a webserver that supports car-mirror requests running:
21//! tokio::spawn(car_mirror_axum::serve(MemoryBlockStore::new()));
22//!
23//! // You can issue requests from your client like so:
24//! let store = MemoryBlockStore::new();
25//! let data = b"Hello, world!".to_vec();
26//! let root = store.put_block(data, CODEC_RAW).await?;
27//!
28//! let client = Client::new();
29//! client
30//!     .post(format!("http://localhost:3344/dag/push/{root}"))
31//!     .run_car_mirror_push(root, &store, &NoCache) // rounds of push protocol
32//!     .await?;
33//!
34//! let store = MemoryBlockStore::new(); // clear out data
35//! client
36//!     .post(format!("http://localhost:3344/dag/pull/{root}"))
37//!     .run_car_mirror_pull(root, &Config::default(), &store, &NoCache) // rounds of pull protocol
38//!     .await?;
39//!
40//! assert!(store.has_block(&root).await?);
41//! # Ok(())
42//! # }
43//! ```
44
45mod error;
46mod request;
47
48pub use error::*;
49pub use request::*;