seanmonstar / reqwest

An easy and powerful Rust HTTP Client
https://docs.rs/reqwest
Apache License 2.0
9.91k stars 1.12k forks source link

Split out the async facade pattern into a crate? #191

Open Korvox opened 7 years ago

Korvox commented 7 years ago

Currently having a conversation over at inth-oauth2 about how to proceed in an async world. There are basically two arguments I see in the general use case:

  1. Everyone should just use reqwest and abstract over both the sync and async impls, providing two split apis in the same design. This has some issues, like constraining consumers to using reqwests tls crate.
  2. Wrap hyper directly, which is desirable to avoid going through a wrapper, and having access to sharing hyper pieces like the client. Then you need to provide a sync api on top of that for ease of use in small use cases. Right now that is a completely manual exercise, and as reqwest itself demonstrates can take a huge amount of code to make solid.

Since reqwest already did the second option, and in a cursory glance a good 1/3 of all the code in reqwest right now is just in implementing the async facade for the default sync api, it would probably be a good idea to split out reusable functionality into its own crate as a library support helper for hyper libs that want to provide both async and sync versions of their api. Then everyone can still directly use hyper with their async "core" api, but provide a sync wrapper with all the channel / oneshot / thread / event loop boilerplate coming from hyper-sync-wrapper or whatever you would want to call it.

PoiScript commented 7 years ago

Actually, reqwest already have async but still in unstable... https://github.com/seanmonstar/reqwest/blob/master/tests/async.rs

Korvox commented 7 years ago

Thats the point. Since v0.7 Reqwest has been based on async hyper but hides the async impl behind its sync layer. This pattern is useful for any library using hyper that wants to provide the same facade and could probably be crated up independently of reqwest and reused in a lot of crates.

PoiScript commented 7 years ago

Yes, I can see that they're still working on it. If they can provide something of roadmap, it will be better.

seanmonstar commented 7 years ago

I had hoped to be able to make a separate crate, but quickly found that I wanted to be able to use private APIs, either with creating errors, building a client, building requests, using bodies... So it ended up in one crate.

I'm not against the idea, just providing the information for why it ended up in one crate for now.