-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
The current wasm implementation supports compiling to wasm with wasm_bindgen
, which is meant to provide bindings for usage from JavaScript in the browser. This aligns with many of the concepts from wasi_preview_1 and uses the browser's fetch()
API to actually make the request. This works great for the browser, now there's tons of applications that want to use a higher level API for making requests from Wasm and run them on the server. The next iteration of WASI, wasi_preview_2, is the perfect basis for this.
WASI Preview 2 released earlier this year WebAssembly/WASI#577 with a common set of standard interfaces, including wasi-http
which provides an interface both for incoming and outgoing HTTP requests. What I would love is for reqwest
to support binding to wasi:http/outgoing-handler
which would let Rust devs compile reqwest directly to a Wasm component targeting p2. I am a maintainer of wasmCloud which uses wasi-http for it's requests and, as you can see in this sample, using a higher level library in Rust greatly simplifies the code.
I opened #2290 to start implementing this but I think there's a couple of questions to answer:
- How do we want to gate compiling for the browser v.s. compiling to a component? Is it feature flags, and if so, which one is the default? (It's worth noting there is a specific target for components, wasm32-wasip2, however this is a new target and doesn't properly denote the difference between "browser" wasm and a component)
- Does feat(wasm): add support for wasip2, aka webassembly components, using
wasi-http
#2290 look reasonable or should we approach the problem differently? Most of the logic happens in the client'sfetch
function, and you can see the translation from the reqwest::Request and the wasi::http::OutgoingRequest. - Do we like the file organization in feat(wasm): add support for wasip2, aka webassembly components, using
wasi-http
#2290 with the refactor or prefer for components to be a new folder? WASI Http module #1956 contains a reference implementation with slightly old bindings with a different file structure
This PR is essentially a duplicate of #1956, I just promised to open another issue so we can dedup as necessary.
I think this PR is related to #1977 but it might not entirely supercede it since there's a deeper discussion on abstraction.
Thanks @seanmonstar for being receptive to the issue + change. Looking forward to the discussion!