Hello,
I was going to submit a PR to add async support as a optional feature to this crate and wanted to see if that is something you would consider merging. Since ureq does not have async support, I would add an optional dependancy on the reqwest, tokio and async-trait crate and implement a call_async function in the BaseApi trait something like:
#[cfg(feature = "async")]
use async_trait::async_trait;
#[cfg_attr(feature = "async", async_trait)]
pub trait BaseApi<'a>
where
Self::Model: Serialize + for<'de> Deserialize<'de>
{
type Model;
...
#[cfg(feature = "async")]
async fn call_async(&self) -> Result<Self::Model, reqwest::Error> {
// TODO: Add implementation
}
}
A client than could call the API via
let result = client.forecast()
.query(Query::City("London".to_string()))
.dt(Utc.ymd(2022, 08, 21).and_hms(0, 0, 0))
.lang(Language::Spanish)
.call_async()
.await;
The Cargo.toml file would be updated to add the optional async feature.
[features]
default = []
async = ["dep:reqwest", "dep:tokio", "dep:async_trait"]
[dependencies]
reqwest = { version = "0.11", features = ["json"], optional = true }
tokio = { version = "1", features = ["full"], optional = true }
async-trait = { version = "0.1", optional = true }
If you don't like having both ureq and reqwest dependancies, reqwest has support for both blocking and async libraries. I could rewrite the current code to use reqwest instead of ureq eliminating the need for two different HTTP libraries. Let me know what you think, this would be a completely optional feature so the default would be opt-out and would not increase the code size by default. Thanks and awesome crate.
Hello,
I was going to submit a PR to add async support as a optional feature to this crate and wanted to see if that is something you would consider merging. Since ureq does not have async support, I would add an optional dependancy on the reqwest, tokio and async-trait crate and implement a
call_asyncfunction in theBaseApitrait something like:A client than could call the API via
The Cargo.toml file would be updated to add the optional
asyncfeature.If you don't like having both
ureqandreqwestdependancies,reqwesthas support for both blocking and async libraries. I could rewrite the current code to usereqwestinstead ofureqeliminating the need for two different HTTP libraries. Let me know what you think, this would be a completely optional feature so the default would be opt-out and would not increase the code size by default. Thanks and awesome crate.