wasmcloud-actor-keyvalue

Crates.iowasmcloud-actor-keyvalue
lib.rswasmcloud-actor-keyvalue
version0.2.2
sourcesrc
created_at2021-02-10 16:01:38.860213
updated_at2021-04-16 15:54:18.471682
descriptionInterface to the key-value contract for use by wasmCloud Actors
homepage
repository
max_upload_size
id353268
size18,905
wasmCloud Automation Bot (wasmcloud-automation)

documentation

https://docs.rs/wasmcloud-actor-keyvalue

README

crates.io  Rust license  documentation

wasmCloud Key Value Store Actor Interface

This crate provides an interface for actors to use to communicate with a key-value store capability provider. Actors using this interface must have the wasmcloud:keyvalue capability permission.

This crate is one-way, and only supports actors making calls to the host. The capability provider does not deliver messages to actors (e.g. actors cannot subscribe to store change events).

The following is an example usage:

#[macro_use]
extern crate serde_json;
extern crate wasmcloud_actor_http_server as http;
extern crate wasmcloud_actor_keyvalue as kv;
extern crate wasmcloud_actor_core as actor;

use http::{self, Request, Response};
use wascap_guest::HandlerResult;

#[macro_use]
extern crate serde_json;

#[actor::init]
pub fn init() {
    http::Handlers::register_handle_request(increment_counter);
}

fn increment_counter(msg: Request) -> HandlerResult<Response> {
    let key = msg.path.replace('/', ":");
    let resp = kv::default().add(key.to_string(), 1)?;

    let result = json!({"counter": resp.value });
    Ok(Response::json(result, 200, "OK")?)
}
Commit count: 0

cargo fmt