feat: add gloo-net HTTP backend for WASM targets #1272
+153,149
−545
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Progenitor previously only supported the
reqwestHTTP backend, which adds bundle size overhead for WASM/browser applications. Thegloo-netlibrary is specifically designed for WASM targets and leverages the browser's native Fetch API.This means we get smaller bundle sizes, better integration with browser APIs (WebSocket, streaming, etc.), and the native browser behavior for connection pooling, timeouts, and TLS. This change adds first-class support for
gloo-netas an alternative HTTP backend.progenitor-impl: AddedHttpBackendenum (Reqwest|Gloo) to represent backend choice throughout code generationprogenitor-client: Implementedgloo_impl.rswith feature parity toreqwest_impl.rs:Error<E>enumResponseValue<T>wrapper for responses with status/headersByteStreamsupport viawasm_streamsfor streaming responsesweb_sys::WebSocketdirectly, rather than HTTP upgrade (since browsers don't exposeWebSocketas an HTTP upgrade)shared.rsfor both backendscargo-progenitor: Added--backendCLI flag (defaults toreqwest) to generate backend-specific code and dependenciesbackendparameter togenerate_api!macrobuild.rs: Addedwith_backend()method toGenerationSettingsexample-wasm/was updated to demonstrate gloo backend usage withHttpBackend::Glooinbuild.rsDesign Decisions
reqwest-clientandgloo-clientinto mutually exclusive features, for the following reasons:reqwestvsgloo-net/web-sys), including some existing dependencies that need to have optional features enabledreqwest::ErrorvsString/serde_json::Error)progenitor-client/src/lib.rsenforces this with compile-time errors. To avoid the same error,example-wasmis excluded from the workspace: it depends onprogenitor-clientwithgloo-client, whereascargo-progenitordepends onprogenitor-clientwithreqwest-client.--backend gloowith the--include-clientflag, which is supposed to inlineprogenitor-clientcode. It's theoretically possible, but I realized the following:wasm-bindgen,web-sys,js-sys) that we'd have to enableusestatementswasm32-unknown-unknownusually have some form of more complex build process using tools likewasm-packortrunkanywayInstead it returns an error message directing users to use the dependency instead.
reqwestdoes something likeClient::new_with_client(url, reqwest::Client), and all configuration happens at construction time.gloo-netuses theClientHookstrait with thepre()andpost()hooks, which allow per-request customization of the Fetch APIRequestInitoptions.Usage
For WASM applications wanting to use the gloo backend: