Skip to content

feat: implement Fetch function and FetchResponse type for HTTP requests#3

Merged
pikann merged 3 commits into
masterfrom
feature/implement-fetch-function-for-http-request
May 13, 2026
Merged

feat: implement Fetch function and FetchResponse type for HTTP requests#3
pikann merged 3 commits into
masterfrom
feature/implement-fetch-function-for-http-request

Conversation

@pikann
Copy link
Copy Markdown
Contributor

@pikann pikann commented May 13, 2026

This pull request introduces a new outbound HTTP request capability for WASM plugins by adding a Fetch API, along with the supporting types and host function bindings. The changes are organized into two main themes: the implementation of the Fetch API for WASM builds, and the addition of stubs for non-WASM builds to maintain compatibility.

New Fetch API for WASM plugins:

  • Added a FetchResponse struct and a Fetch function to wasm_backends.go, enabling outbound HTTP requests from WASM plugins via the paca.fetch host function. The implementation includes request serialization, host call invocation, and response decoding with error handling.
  • Declared the hostFetch function in wasm_imports.go to bind the WASM import for HTTP requests, allowing WASM code to call out to the host for HTTP operations.
  • Imported the fmt package in wasm_backends.go to support error formatting in the new Fetch implementation.

Non-WASM compatibility:

  • Added a stub FetchResponse struct and a Fetch function in native_backends.go that always returns an error, ensuring non-WASM builds compile and fail gracefully if Fetch is called.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an outbound HTTP request capability for WASM plugins by introducing a new Fetch API and FetchResponse type, plus the corresponding WASM host import binding, while keeping non-WASM builds compiling via stub implementations.

Changes:

  • Added hostFetch WASM import binding for the paca.fetch host function.
  • Implemented Fetch and FetchResponse for wasip1 builds with JSON request/response marshalling.
  • Added non-WASM stubs for Fetch / FetchResponse that return errNotWASM.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
wasm_imports.go Adds the paca.fetch host import binding (hostFetch).
wasm_backends.go Implements Fetch + FetchResponse for WASM, including host-call wiring and response decoding.
native_backends.go Adds non-WASM stubs for Fetch and FetchResponse to preserve build compatibility.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread wasm_backends.go
Copilot finished work on behalf of pikann May 13, 2026 10:27
@pikann pikann merged commit d21237f into master May 13, 2026
3 checks passed
@pikann pikann deleted the feature/implement-fetch-function-for-http-request branch May 13, 2026 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants