|
| 1 | +# Blank Slate Capability Provider |
| 2 | + |
| 3 | +This capability provider is a blank slate for creating providers with custom capabilities. It uses the [wasmcloud-provider-sdk](https://crates.io/crates/wasmcloud-provider-sdk) and implements the [Provider](https://docs.rs/wasmcloud-provider-sdk/0.5.0/wasmcloud_provider_sdk/trait.Provider.html) trait with an example handler that will persist the links that target the provider (target links) and links where the provider is the source and targets a component (source links). |
| 4 | + |
| 5 | +The purpose of this example is to provide comprehensive comments on the usage of our wasmCloud provider SDK, from serving RPC exports to invoking component imports. The code is informative to read through and provides a base for extending wasmCloud with custom capabilities. |
| 6 | + |
| 7 | +## Building |
| 8 | + |
| 9 | +Prerequisites: |
| 10 | + |
| 11 | +1. [Rust toolchain](https://www.rust-lang.org/tools/install) |
| 12 | +1. [wash](https://wasmcloud.com/docs/installation) |
| 13 | + |
| 14 | +You can build this capability provider by running `wash build`. You can build the included test component with `wash build -p ./component`. |
| 15 | + |
| 16 | +## Running to test |
| 17 | + |
| 18 | +Prerequisites: |
| 19 | + |
| 20 | +1. [Rust toolchain](https://www.rust-lang.org/tools/install) |
| 21 | +1. [nats-server](https://github.com/nats-io/nats-server) |
| 22 | +1. [nats-cli](https://github.com/nats-io/natscli) |
| 23 | + |
| 24 | +You can run this capability provider as a binary by passing a simple base64 encoded [HostData](https://docs.rs/wasmcloud-core/0.6.0/wasmcloud_core/host/struct.HostData.html) struct, in order to do basic testing. For example: |
| 25 | + |
| 26 | +```bash |
| 27 | +nats-server -js & |
| 28 | +echo '{"lattice_rpc_url": "0.0.0.0:4222", "lattice_rpc_prefix": "default", "provider_key": "blank-slate", "config": {"foo": "bar"}, "env_values": {}, "link_definitions": [], "otel_config": {"enable_observability": false}}' | base64 | cargo run |
| 29 | +``` |
| 30 | + |
| 31 | +And in another terminal, you can request the health of the provider using the NATS CLI |
| 32 | + |
| 33 | +```bash |
| 34 | +nats req "wasmbus.rpc.default.blank-slate.default.health '{}' |
| 35 | +``` |
| 36 | +
|
| 37 | +Additionally, you can invoke the provider directly which will send test data to each linked component |
| 38 | +
|
| 39 | +```bash |
| 40 | +wash call blank-slate wasmcloud:example/system-info.call |
| 41 | +``` |
| 42 | +
|
| 43 | +## Running as an application |
| 44 | +
|
| 45 | +You can deploy this provider, along with a [prebuilt component](./component/) for testing, by deploying the [wadm.yaml](./wadm.yaml) application. |
| 46 | +
|
| 47 | +```bash |
| 48 | +# Launch wasmCloud in the background |
| 49 | +wash up -d |
| 50 | +# Deploy the application |
| 51 | +wash app deploy ./wadm.yaml |
| 52 | +``` |
| 53 | +
|
| 54 | +## Customizing |
| 55 | +
|
| 56 | +Customizing this provider to meet your needs of a custom capability takes just a few steps. |
| 57 | +
|
| 58 | +1. Update the [wit/world.wit](./wit/world.wit) to include the data types and functions that model your custom capability. You can use the example as a base and the [component model WIT reference](https://component-model.bytecodealliance.org/design/wit.html) as a guide for types and keywords. |
| 59 | +1. Implement any provider `export`s in [src/provider.rs](./src/provider.rs) inside of the `impl Handler {}` block. |
| 60 | +1. Use the methods inside of the `impl Provider {}` block to handle invoking components. For inspiration, take a look at our other capability providers that implement various capabilities like HTTP, Messaging, Key-Value in the [crates/provider-\*](../../../../crates/) folder. |
| 61 | +
|
| 62 | +Have any questions? Please feel free to [file an issue](https://github.com/wasmCloud/wasmCloud/issues/new/choose) and/or join us on the [wasmCloud slack](https://slack.wasmcloud.com)! |
0 commit comments