I love the simple API of this crate! It can be useful if ehttp
supports saving cookies, such as login function. Currently, the "agent" (ureq::Agent type) is not continuous between each request.
A cross-platform and object-oriented example might look like this:
pub struct Agent {
#[cfg(not(target_arch = "wasm32"))]
agent: ureq::Agent,
}
// save the session if we need (compatible syntax)
let session = Agent::new();
session.fetch(req, |r| match r {
Ok(r) if r.ok => alert("Login successfully!"),
_ => alert("Login failed!"),
});
// original "fetch" function
fetch(req, |r| match r {
Ok(r) if r.ok => alert("Login successfully!"),
_ => alert("Login failed!"),
});