HTTP Server
A simple HTTP server with multiple endpoints, implemented as a Wasm component and packaged for Cosmonic Control.
Deploy with Helm
helm install http-server --version 0.1.2 oci://ghcr.io/cosmonic-labs/charts/http-trigger -f https://raw.githubusercontent.com/cosmonic-labs/control-demos/refs/heads/main/http-server/values.http-trigger.yamlRepository: cosmonic-labs/control-demos/http-server
Languages: Go
Interfaces: wasi/http
Running on Kubernetes
You will need a local Kubernetes environment with Cosmonic Control installed according to the Get Started guide.
Connect to the component at http://http-server.localhost.cosmonic.sh:
curl http://http-server.localhost.cosmonic.shSend a request
You can send a request to the following endpoints:
GET /
Returns a list of available endpoints and their descriptions.
curl http://http-server.localhost.cosmonic.sh/ /error - return a 500 error
/form - echo the fields of a POST request
/headers - echo your user agent back as a server side header
/post - echo the body of a POST requestGET /error
Returns a 500 Internal Server Error.
curl -v http://http-server.localhost.cosmonic.sh/error< HTTP/1.1 500 Internal Server Error
< content-type: text/plain; charset=utf-8
<
Something went wrongGET /headers
Returns your User-Agent in the response headers.
curl -v http://http-server.localhost.cosmonic.sh/headers< HTTP/1.1 200 OK
< x-your-user-agent: curl/8.7.1
<
Check headers!POST /form
Echoes back form data from a POST request.
curl -X POST -d "field1=value1&field2=value2" http://http-server.localhost.cosmonic.sh/formfield2: value2
field1: value1POST /post
Echoes back the entire body of a POST request.
curl -X POST -d "Hello World" http://http-server.localhost.cosmonic.sh/postHello WorldDevelopment
Development requirements:
tinygofor compiling Gowasm-toolsfor Go bindingswashv2.0.0-rc.7 for building the component
Clone the cosmonic-labs/control-demos repository:
git clone https://github.com/cosmonic-labs/control-demos.gitcd control-demos/http-serverStart the development loop:
wash devWhen using wash dev, the HTTP Server is accessible at localhost:8000. View the code and make changes in main.go.
You can cancel the wash dev process with Ctrl-C.
Build the Wasm Binary
Compile the component:
wash buildThe .wasm binary will output to ./build.
Learn More
- See the wasmCloud Developer Guide for instructions on pushing your Wasm component to an OCI registry.
-
To learn how to extend this example with additional capabilities, see the Adding Capabilities section of the wasmCloud documentation.
-
For more on building components in Go, see the Component Developer Guide in the wasmCloud documentation.