This proof-of-concept takes the web-sys/fetch example at the wasm-bindgen website and adapts it so it can be used as a Cloudflare worker.
To generate the required files for a Cloudflare worker, the excellent template for kick starting a Cloudflare worker project using
wasm-pack
was used.
- The example at the wasm-bindgen website uses the websys::window() function to send out the request to the API. However, websys::Window context is not usable in a Cloudflare Worker (as there is no window). In this case the websys::Worker context should be used.
- The GitHub API now requires for the calling logic to send a HTTP Header "UserAgent".
- opts.mode(RequestMode::Cors); >>> This line had to be removed, because the mode setting of the request is not implemented by CloudFlare.