Go HTTP Password Checker
This example is a WebAssembly component that checks password strength over HTTP.
The application...
- Implements a
wasi:http
-compliant HTTP handler - Uses the
httpserver
provider to serve requests - Can be declaratively provisioned in a wasmCloud environment
📦 Dependencies
Before starting, ensure that you have the following installed in addition to the Go (1.23+) toolchain:
tinygo
for compiling Go (always use the latest version)wasm-tools
for Go bindings- wasmCloud Shell (
wash
) for building and running the components and wasmCloud environment
👟 Run the example
Clone the wasmCloud/go repository:
git clone https://github.com/wasmCloud/go.git
Change directory to examples/component/http-password-checker
:
cd examples/component/http-password-checker
In addition to the standard elements of a Go project, the example directory includes the following files and directories:
build/
: Target directory for compiled.wasm
binariesgen/
: Target directory for Go bindings of interfaceswit/
: Directory for WebAssembly Interface Type (WIT) packages that define interfacesbindings.wadge_test.go
: Automatically generated test bindingswadm.yaml
: Declarative application manifestwasmcloud.lock
: Automatically generated lockfile for WIT packageswasmcloud.toml
: Configuration file for a wasmCloud application
Start a local development loop
Run wash dev
to start a local development loop:
wash dev
The wash dev
command will:
- Start a local wasmCloud environment
- Build this component
- Deploy your application and all requirements to run the application locally, including...
- Your locally built component
- The HTTP server provider, which will receive requests from the outside world (on port 8000 by default)
- Necessary links between providers and your component so your component can handle web traffic
- Watch your code for changes and re-deploy when necessary.
Once the application is deployed, open another terminal tab. To ensure that the application has reached Deployed
status, you can use wash app list
:
wash app list
Send a request
You can send a request with a JSON payload to the /api/v1/check
endpoint:
curl localhost:8000/api/v1/check -d '{"value": "tes12345!"}'
{
"valid": false, "message": "insecure password, try including more special characters, using uppercase letters or using a longer password"
}
Clean up
You can cancel the wash dev
process with Ctrl-C
.
⚠️ Issues/FAQ
curl
produces a "failed to invoke" error
If curl
ing produces...
failed to invoke `wrpc:http/incoming-handler.handle`: failed to invoke `wrpc:http/incoming-handler@0.1.0.handle`: failed to shutdown synchronous parameter channel: not connected%
...the HTTP server may not have finished starting up. You can check that the application has reached Deployed
status with wash app list
.
If the issue persists, you may have a lingering HTTP server provider running on your system. You can use pgrep
to check:
pgrep -la ghcr_io
4007604 /tmp/wasmcloudcache/NBCBQOZPJXTJEZDV2VNY32KGEMTLFVP2XJRZJ5FWEJJOXESJXXR2RO46/ghcr_io_wasmcloud_http_server_0_23_1
📖 Further reading
To learn how to extend this example with additional capabilities, see the Adding Capabilities section of the wasmCloud documentation.
For more on building components, see the Component Developer Guide in the wasmCloud documentation.