-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow customization of reqwest client #33
Comments
Thanks for the issue, you raise a good point. But I'm a little wary of allowing people to supply their own clients because I feel that it would go against the "idea" of a wrapper which is to try to keep people away from the lower level details like this and not have to worry about any other libraries (maybe except Tokio, but that's almost required when using async Rust). Instead, what's your opinion on passing a config struct to roux which will build the client for you? I think this is better because it would prevent you from having to manually set the things roux does like auth headers (I know |
I don't think there is "the one" right approach of supporting customization here, and my suggestion of providing a custom I'm not that familiar with the In any case, I guess it would be a feature for more advanced users, so I do think a little complexity is OK as long as there's the regular old "it just works" API that you currently have. And perhaps there is even a middle way, for example the possibility to create your own To be honest, I don't really care too much about the precise details, and I trust that you as the library author are probably in the best position to judge which approach is most appropriate. |
I think my preferred method would be to allow the user to supply their own client, or maybe they could just configure it using a closure. pub use reqwest::ClientBuilder as ReqwestBuilder;
impl Reddit {
/// Creates a `Reddit` instance with user_agent, client_id, and client_secret, and
/// provides a ClientBuilder that allows the user to configure the inner request client.
pub fn new_with_options<F>(
user_agent: &str,
client_id: &str,
client_secret: &str,
options: F,
) -> Result<Reddit, RouxError>
where
F: FnOnce(ReqwestBuilder) -> ReqwestBuilder,
{
Ok(Reddit {
config: config::Config::new(user_agent, client_id, client_secret),
client: options(Client::builder()).build()?,
})
}
} |
Currently,
roux::Subreddit
usesreqwest::Client
with its default settings, which might not be applicable to all use cases. For example, the defaultClient
does not have any timeouts, so if connectivity is lost then requests simply hang indefinitely.I'd like the possibility to supply my own
Client
instance when creating aSubreddit
instance.The text was updated successfully, but these errors were encountered: