Skip to content

dicej/go-wasi-http-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-wasi-http-example

This demonstrates how to implement a wasi:[email protected] handler using Go, based on a new wit-bindgen-go bindings generator which supports idiomatic, goroutine-based concurrency on top of the Component Model concurrency ABI.

As of this writing, not everything has been upstreamed and released, so this relies on specific Git revisions of certain tools, plus a patched version of Go. Once everything is merged, we'll be able to switch to the upstream releases.

Building and Running

Prerequisites

  • Rust 1.91 or later
  • Make
  • Curl

This will build the dependencies, generate Go bindings from the wasi:[email protected] WIT files, build the component, and run it using wasmtime serve:

make run

While that's running, you can send a request from another shell:

curl -i http://127.0.0.1:8080/hello

If all goes well, you should see hello, world!.

You can also try the other endpoints, e.g. /echo, which does full-duplex streaming:

curl -i -H 'content-type: text/plain' --data-binary @- http://127.0.0.1:8080/echo <<EOF
’Twas brillig, and the slithy toves
      Did gyre and gimble in the wabe:
All mimsy were the borogoves,
      And the mome raths outgrabe.
EOF

...and /hash-all, which concurrently downloads one or more URLs and streams the SHA-256 hashes of their contents:

curl -i \
    -H 'url: https://webassembly.github.io/spec/core/' \
    -H 'url: https://www.w3.org/groups/wg/wasm/' \
    -H 'url: https://bytecodealliance.org/' \
    http://127.0.0.1:8080/hash-all

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published