Crate spirit_reqwest
source ·Expand description
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. Together,
they form a CfgHelper
.
Examples
use serde_derive::Deserialize;
use spirit::{Empty, Spirit};
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()
.config_helper(Cfg::client, &client, "client")
.run(move |_| {
let page = client
.get("https://www.rust-lang.org")
.send()?
.error_for_status()?
.text()?;
println!("{}", page);
Ok(())
});
}