Support more HTTP clients
We currently support reqwest.
It would be nice to have other possibilities as well, for example surf
Hello! I am trying to imagine how to add some more clients.
First of all I would like to add awc client. But I also thought how to add more clients...
It seems to me, that it must be one struct with client field and client method like this:
pub struct KeycloakAdmin {
#[cfg(feature = "reqwest-client")]
client: reqwest::Client,
#[cfg(feature = "awc-client")]
client: awc::Client,
#[cfg(feature = "hyper-client")]
client: hyper::client::conn::http1::SendRequest<String>,
config: KeycloakConfig, // with url, user, pass, realm, client_id, grant_type fields
}
impl KeyCloakAdmin {
async fn post_request(&self) {
#[cfg(feature = "reqwest-client")]
reqwest_client(&self.config);
#[cfg(feature = "awc-client")]
awc_client(&self.config);
#[cfg(feature = "hyper-client")]
hyper_client(&self.config);
}
async fn get_request(&self) {
#[cfg(feature = "reqwest-client")]
reqwest_client(&self.config);
#[cfg(feature = "awc-client")]
awc_client(&self.config);
#[cfg(feature = "hyper-client")]
hyper_client(&self.config);
}
// ...
}
There are some other thoughts.. But there also some points which I do not understand. First of all how do you generate code in generated_rest.rs module, do you use openapi-generator? How can it work with clients abstractions?
@ArtyomSinyugin this is a good question(s).
My idea was to use intermediate adapter to support whatever can come. Basically, rely on some external library with trait definition defaulting to reqwest or that is specified as default through feature activation. I think there is already existing crate for this, at least there was one 4 years ago, probably situation improved nowadays.
Why I have not implemented it so far? No one showed interest to this issue, so not much reason to think about. As you seems to be interested in this feature, we can think about implementation.
Ideally would be to have compatibility traits defined on Rust Foundation level, because keeping short list of good crates IMHO leaves us a little bit out of enterprise demands.
The code is generated using examples/openapi.rs.
@kilork Thank you. I will try to think about the solution.