Summary
I've implemented an HTTP library for go-plugin that enables WASM plugins to make HTTP requests. Since WASM doesn't support Go's standard net/http package, this library provides HTTP capabilities through host function proxying using the host-function-library pattern.
Repository: https://github.com/hanxi/go-plugin-http
Features
- Provides
net/http-like API for WASM plugins (Get, Post, Head, Do, etc.)
- Supports custom headers, request body, and timeout
- Uses the
host-function-library pattern (similar to examples/host-function-library)
- Works with Go 1.24+ and
-buildmode=c-shared for WASI reactor
Usage Example
Host Side
import (
httpexport "github.com/hanxi/go-plugin-http/export"
httpimpl "github.com/hanxi/go-plugin-http/impl"
)
p, err := proto.NewGreeterPlugin(ctx, proto.WazeroRuntime(func(ctx context.Context) (wazero.Runtime, error) {
r, err := proto.DefaultWazeroRuntime()(ctx)
if err != nil {
return nil, err
}
// Inject HTTP Library
return r, httpexport.Instantiate(ctx, r, httpimpl.HttpLibraryImpl{})
}))
Plugin Side
import http "github.com/hanxi/go-plugin-http/plugin"
resp, err := http.Get("https://example.com/api")
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
Questions
I think this library could be useful for the go-plugin community. I have two questions:
-
Would you be interested in adding this as an example in examples/?
- I could submit a PR to add it as
examples/http-library or similar
-
Or would you prefer to add a link to this library in the README?
- Perhaps in a "Community Libraries" or "Related Projects" section
I'm happy to contribute in whatever way works best for the project. Let me know your thoughts!
Related
- This library was inspired by the
host-function-library example
- Tested with go-plugin v0.9.0 and wazero v1.11.0
Summary
I've implemented an HTTP library for go-plugin that enables WASM plugins to make HTTP requests. Since WASM doesn't support Go's standard
net/httppackage, this library provides HTTP capabilities through host function proxying using thehost-function-librarypattern.Repository: https://github.com/hanxi/go-plugin-http
Features
net/http-like API for WASM plugins (Get,Post,Head,Do, etc.)host-function-librarypattern (similar toexamples/host-function-library)-buildmode=c-sharedfor WASI reactorUsage Example
Host Side
Plugin Side
Questions
I think this library could be useful for the go-plugin community. I have two questions:
Would you be interested in adding this as an example in
examples/?examples/http-libraryor similarOr would you prefer to add a link to this library in the README?
I'm happy to contribute in whatever way works best for the project. Let me know your thoughts!
Related
host-function-libraryexample