seed
seed copied to clipboard
Incorporating standalone HTTP crates
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.
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.
Agree - unable to get either to compile to wasm target on stable. Will re-attack later.
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.
obsolete since v0.10.0