seed icon indicating copy to clipboard operation
seed copied to clipboard

Incorporating standalone HTTP crates

Open David-OConnor opened this issue 6 years ago • 3 comments

Until recently, using web_sys's fetch functionality's been the only practical way to perform HTTP requests. Recently, two new options became available:

Surf is a just-release async HTTP crate with WASM support. Reqwest, a popular Rust HTTP crate recently added WASM support.

Thoughts on using one of these along with, or instead of the existing fetch module? I haven't explored this yet, and how it would work with the update system. Users can always, of course, use these separately with no direct integration.

David-OConnor avatar Sep 23 '19 10:09 David-OConnor

On the first look:

  • Surf seems to be too young - for example I didn't found functions to set timeout.
  • Reqwest's WASM support is WIP - https://github.com/seanmonstar/reqwest/pull/630.
  • I don't know if any of them will support cancelling in-flight requests (https://developer.mozilla.org/en-US/docs/Web/API/AbortController).
  • We can't use async/.await, because it's not stable yet.

So I suggest to wait until we can use async/.await and Reqwest fully supports WASM. Then we can experiment with them or/and rewrite our Fetch module. However it's a pain to support our custom API wrappers, we should use external libraries as much as possible if it makes Seed's code simpler and there aren't problems with public API. In other words - outsource work on common components and focus on Seed.

MartinKavik avatar Sep 23 '19 12:09 MartinKavik

Agree - unable to get either to compile to wasm target on stable. Will re-attack later.

David-OConnor avatar Sep 25 '19 05:09 David-OConnor

Reqwest, Surf and probably other libraries depends on rust-url, which can be problem - see https://github.com/servo/rust-url/issues/557#issuecomment-544917435.

So we probably have to create alternative to rust-url which would have the same public API like rust-url but use browser's URL. It would help also with Seed's core - see PR https://github.com/David-OConnor/seed/pull/253.

MartinKavik avatar Oct 22 '19 11:10 MartinKavik

obsolete since v0.10.0

flosse avatar Mar 07 '23 00:03 flosse