---
title: "Develop a Wasm Component for wasmCloud | wasmCloud"
description: "Add capabilities like HTTP, key-value, and logging to your WebAssembly component using standard WASI interfaces and the Wasm component model."
canonical: "https://wasmcloud.com/docs/quickstart/develop-a-webassembly-component/"
---

Version: v2

# Develop a Wasm Component for wasmCloud

Once you know what your application needs to be able to do, you can add language-agnostic [**interfaces**](https://wasmcloud.com/docs/overview/interfaces/) to access capabilities like HTTP, key-value storage, or logging.

In this step, we'll discuss how to:

- Update our application to accept a name and return a personalized greeting.
- Add more features to our application by plugging in **key-value** and **logging** capabilities.

> **Prerequisites**
>
> This tutorial assumes you're following directly from the previous tutorial. If you don't have a "Hello world" application running, complete [**Quickstart**](https://wasmcloud.com/docs/quickstart/) first.

## Add functionality

**Rust**

Let's extend this application to do more than just say "Hello!"

We can check the request for a name provided in a query string, and then return a greeting with that name. If there isn't one or the path isn't in the format we expect, we'll default to saying "Hello, World!"

rust

```rust
use wstd::http::{Body, Request, Response, StatusCode};

#[wstd::http_server]
async fn main(req: Request<Body>) -> Result<Response<Body>, wstd::http::Error> {
    match req.uri().path() {
        "/" => home(req).await,
        _ => not_found(req).await,
    }
}

async fn home(_req: Request<Body>) -> Result<Response<Body>, wstd::http::Error> {
async fn home(req: Request<Body>) -> Result<Response<Body>, wstd::http::Error> {
  // Parse query string for name parameter
    let query = req.uri().query().unwrap_or("");
    let name = match query.split("=").collect::<Vec<&str>>()[..] {
            ["name", name] => name,
            _ => "World",
        };
  // Return a simple response with a string body
    Ok(Response::new("Hello from Wasm!\n".into()))
    Ok(Response::new(format!("Hello, {name}!\n").into()))
}

async fn not_found(_req: Request<Body>) -> Result<Response<Body>, wstd::http::Error> {
    Response::builder()
        .status(StatusCode::NOT_FOUND)
        .body("Not found\n".into())
        .map_err(Into::into)
}
```

**TypeScript**

Let's extend this application to do more than just say "Hello!"

Using Hono's built-in query parameter parsing, we can check the request for a name provided in a query string, and then return a greeting with that name. If there isn't one, we'll default to saying "Hello, World!"

typescript

```typescript
import { Hono } from 'hono';
import { fire } from '@bytecodealliance/jco-std/wasi/0.2.x/http/adapters/hono/server';

const app = new Hono();

app.get('/', (c) => {
  return c.text('Hello from Wasm!\n');
  const name = c.req.query('name') || 'World';
  return c.text(`Hello, ${name}!\n`);
});

app.notFound((c) => {
  return c.text('Not found\n', 404);
});

fire(app);

export { incomingHandler } from '@bytecodealliance/jco-std/wasi/0.2.x/http/adapters/hono/server';
```

**My language isn't listed**

If you prefer working in a language that isn't listed here, let us know!

Loading...

After saving your changes, your toolchain automatically builds and runs the updated application.

We can `curl` the application again:

shell

```shell
curl localhost:8000
```

text

```text
Hello, World!
```

shell

```shell
curl 'localhost:8000?name=Bob'
```

text

```text
Hello, Bob!
```

## Add persistent storage

Now let's add persistent storage to keep a record of each person that this application greeted.

We'll use the **key-value capability** for this. We don't need to pick a library or a specific vendor implementation—all we have to do is add the `wasi:keyvalue` interface to our component.

We can use the [`wasi:keyvalue`](https://github.com/WebAssembly/wasi-keyvalue) interface for interacting with a key-value store.

Interfaces are declared in **WIT (WebAssembly Interface Types)** files. A WIT file is a language-neutral contract describing what your component imports (capabilities it consumes) and exports (functions it exposes). Adding an `import` line to your component's WIT `world` tells the runtime to provide that capability—without binding you to a specific library or vendor. You can read more about WIT on the [Interfaces](https://wasmcloud.com/docs/overview/interfaces/) page.

**Rust**

Before we can use the interface, we'll need to update the `wit/world.wit` file:

wit

```wit
package wasmcloud:hello;

world hello {
  import wasi:keyvalue/store@0.2.0-draft;
  import wasi:keyvalue/atomics@0.2.0-draft;
}
```

**TypeScript**

Before we can use the interface, we'll need to update the `wit/world.wit` file:

wit

```wit
package wasmcloud:templates@0.1.0;

world typescript-http-hello-world-hono {
  import wasi:keyvalue/store@0.2.0-draft;
  import wasi:keyvalue/atomics@0.2.0-draft;

  export wasi:http/incoming-handler@0.2.6;
}
```

**My language isn't listed**

If you prefer working in a language that isn't listed here, let us know!

Loading...

To fetch the new WIT dependencies, we also need to run:

bash

```bash
wash wit fetch
```

**Rust**

We've given our application the ability to perform atomic incrementation and storage operations via the `wasi:keyvalue` interface.

Now we need to add `wit-bindgen` to our `Cargo.toml` so we can generate Rust bindings from the WIT world:

toml

```toml
[dependencies]
wstd = "0.6.3"
wit-bindgen = "0.46.0"
```

Now let's use the atomic increment function to keep track of how many times we've greeted each person.

rust

```rust
use wstd::http::{Body, Request, Response, StatusCode};

// Generate keyvalue bindings from our WIT world
// wstd handles the http export via its macro
wit_bindgen::generate!({
    world: "hello",
    path: "wit",
    generate_all,
});

use wasi::keyvalue::{atomics, store};

#[wstd::http_server]
async fn main(req: Request<Body>) -> Result<Response<Body>, wstd::http::Error> {
    match req.uri().path() {
        "/" => home(req).await,
        _ => not_found(req).await,
    }
}

async fn home(req: Request<Body>) -> Result<Response<Body>, wstd::http::Error> {
    // Parse query string for name parameter
    let query = req.uri().query().unwrap_or("");
    let name = match query.split("=").collect::<Vec<&str>>()[..] {
            ["name", name] => name,
            _ => "World",
        };
    // Open keyvalue bucket and increment counter for this name
    // Note: wasmtime's in-memory keyvalue provider requires empty string as identifier
    let bucket = store::open("")
        .map_err(|e| wstd::http::Error::msg(format!("keyvalue open error: {:?}", e)))?;

    let count = atomics::increment(&bucket, name, 1)
        .map_err(|e| wstd::http::Error::msg(format!("keyvalue increment error: {:?}", e)))?;

    // Return greeting with count
    Ok(Response::new(format!("Hello x{count}, {name}!\n").into()))
    // Return a simple response with a string body
    Ok(Response::new(format!("Hello, {name}!\n").into()))
}

async fn not_found(_req: Request<Body>) -> Result<Response<Body>, wstd::http::Error> {
    Response::builder()
        .status(StatusCode::NOT_FOUND)
        .body("Not found\n".into())
        .map_err(Into::into)
}
```

We've made changes, so once we save, the toolchain will once again automatically update the running application.

> **See the working version**
>
> You can find the end-state Rust component for this section [in the main wasmCloud repo](https://github.com/wasmCloud/wasmCloud/tree/main/examples/http-hello-world-persistent-storage).

**TypeScript**

We've given our application the ability to perform atomic incrementation and storage operations via the `wasi:keyvalue` interface.

Now let's use the atomic increment function to keep track of how many times we've greeted each person.

typescript

```typescript
import { Hono } from 'hono';
import { fire } from '@bytecodealliance/jco-std/wasi/0.2.x/http/adapters/hono/server';

import { increment } from 'wasi:keyvalue/atomics@0.2.0-draft';
import { open } from 'wasi:keyvalue/store@0.2.0-draft';

const app = new Hono();

app.get('/', (c) => {
  const name = c.req.query('name') || 'World';
  return c.text(`Hello, ${name}!\n`);

  // Open keyvalue bucket and increment counter for this name
  const bucket = open('');
  const count = increment(bucket, name, 1);
  return c.text(`Hello x${count}, ${name}!\n`);
});

app.notFound((c) => {
  return c.text('Not found\n', 404);
});

fire(app);

export { incomingHandler } from '@bytecodealliance/jco-std/wasi/0.2.x/http/adapters/hono/server';
```

We've made changes, so once we save, the toolchain will once again automatically update the running application.

> **See the working version**
>
> You can find the end-state TypeScript component for this section [in the `wasmCloud/typescript` repo](https://github.com/wasmCloud/typescript/tree/main/examples/components/http-hello-world-hono-persistent-storage).

**My language isn't listed**

If you prefer working in a language that isn't listed here, let us know!

Loading...

Let's `curl` the component again:

shell

```shell
curl 'localhost:8000?name=Bob'
```

text

```text
Hello x1, Bob!
```

shell

```shell
curl 'localhost:8000?name=Bob'
```

text

```text
Hello x2, Bob!
```

shell

```shell
curl 'localhost:8000?name=Alice'
```

text

```text
Hello x1, Alice!
```

## Next steps

In this tutorial, you added a few more features and persistent storage to a simple microservice. You also got to see the process of developing with capabilities, where you can...

- Write purely functional code that doesn't require you to pick a library or vendor upfront
- Change your application *separately* from its non-functional requirements

So far, `wash` has satisfied our application's capability requirements automatically, so we can move quickly and focus on code. In the [next tutorial](https://wasmcloud.com/docs/quickstart/deploy-a-webassembly-workload/), we'll deploy WebAssembly workloads to wasmCloud on a local Kubernetes cluster.

Last updated on **Jul 1, 2026** by **Eric Gregory**
