ehttp icon indicating copy to clipboard operation
ehttp copied to clipboard

Keep `ureq::Agent` for native clients

Open KmolYuan opened this issue 3 years ago • 1 comments

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!"),
});

KmolYuan avatar Dec 11 '21 04:12 KmolYuan

Good point. We should probably make an API like that, wrapping ureq::Agent.

emilk avatar Feb 28 '23 19:02 emilk