[−][src]Crate spirit_reqwest
This helps with configuring the reqwest
Client
.
This is part of the spirit
system.
There are two levels of support. The first one is just letting the Spirit
to load the
ReqwestClient
configuration fragment and calling create
or builder
on it manually.
The other, more convenient way, is pairing an extractor function with the AtomicClient
and
letting Spirit
keep an up to date version of Client
in there at all times.
Examples
use serde::Deserialize; use spirit::{Empty, Pipeline, Spirit}; use spirit::prelude::*; use spirit_reqwest::{AtomicClient, ReqwestClient}; #[derive(Debug, Default, Deserialize)] struct Cfg { #[serde(default)] client: ReqwestClient, } impl Cfg { fn client(&self) -> ReqwestClient { self.client.clone() } } fn main() { let client = AtomicClient::unconfigured(); // Get a default config before we get configured Spirit::<Empty, Cfg>::new() .with(Pipeline::new("http client").extract_cfg(Cfg::client).install(client.clone())) .run(move |_| { let page = client .get("https://www.rust-lang.org") .send()? .error_for_status()? .text()?; println!("{}", page); Ok(()) }); }
Structs
AtomicClient | A storage for one |
ReqwestClient | A configuration fragment to configure the reqwest |