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 oci://ghcr.io/cosmonic-labs/charts/http-server
Repository: cosmonic-labs/control-demos/http-server
Languages: Go
Interfaces: wasi/http
Requirements: HostGroup with HTTP enabled
Running on Kubernetes
Port-forward the component:
kubectl -n cosmonic-system port-forward svc/hostgroup-default 9091:9091
Now you can connect to the component at localhost:9091
.
Send a request
You can send a request to the following endpoints:
GET /
Returns a list of available endpoints and their descriptions.
curl http://localhost:9091/
/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 request
GET /error
Returns a 500 Internal Server Error.
curl -v http://localhost:9091/error
* Host localhost:9091 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
* Trying [::1]:9091...
* Connected to localhost (::1) port 9091
> GET /error HTTP/1.1
> Host: localhost:9091
> User-Agent: curl/8.7.1
> Accept: */*
>
* Request completely sent off
< HTTP/1.1 500 Internal Server Error
< content-type: text/plain; charset=utf-8
< x-content-type-options: nosniff
< vary: origin, access-control-request-method, access-control-request-headers
< access-control-allow-origin: *
< access-control-expose-headers: *
< transfer-encoding: chunked
< date: Thu, 17 Jul 2025 14:10:53 GMT
<
Something went wrong
* Connection #0 to host localhost left intact
GET /headers
Returns your User-Agent in the response headers.
curl -v http://localhost:9091/headers
* Host localhost:9091 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
* Trying [::1]:9091...
* Connected to localhost (::1) port 9091
> GET /headers HTTP/1.1
> Host: localhost:9091
> User-Agent: curl/8.7.1
> Accept: */*
>
* Request completely sent off
< HTTP/1.1 200 OK
< x-your-user-agent: curl/8.7.1
< vary: origin, access-control-request-method, access-control-request-headers
< access-control-allow-origin: *
< access-control-expose-headers: *
< transfer-encoding: chunked
< date: Thu, 17 Jul 2025 14:09:59 GMT
<
* Connection #0 to host localhost left intact
Check headers!
POST /form
Echoes back form data from a POST request.
curl -X POST -d "field1=value1&field2=value2" http://localhost:9091/form
field2: value2
field1: value1
POST /post
Echoes back the entire body of a POST request.
curl -X POST -d "Hello World" http://localhost:9091/post
Hello World
Development
Development requirements:
tinygo
for compiling Gowasm-tools
for Go bindingswash
for building the component
Clone the cosmonic-labs/control-demos
repository:
git clone https://github.com/cosmonic-labs/control-demos.git
cd control-demos/http-server
Start the development loop:
wash dev
When 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 build
The .wasm
binary will output to ./build
.
Learn More
-
See the Cosmonic Control documentation 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.