Skip to main content
Version: v2.0.0-rc

Quickstart

Build WebAssembly (Wasm) applications and run them across any cloud, Kubernetes, datacenter, or edge.

In this tutorial:

  • We'll use the Wasm Shell (wash) CLI to build a simple "Hello world" HTTP server application as a WebAssembly (Wasm) component—written in the language of your choice.
  • Along the way, we'll start a developer loop that automatically deploys our application to a local wasmCloud environment.

Install wash

First, we need to install the latest version of wash (2.0.0-rc.6).

In your terminal, run the installation script to download and install the latest version of wash:

shell
curl -fsSL https://raw.githubusercontent.com/wasmcloud/wash/refs/heads/main/install.sh | bash

On a successful installation, the script will return:

text
[INFO] Next steps:
  1. Add /path/to to your PATH if not already included
  2. Run 'wash --help' to see available commands
  3. Run 'wash doctor' to verify your environment
  4. Run 'wash new' to create your first WebAssembly component

To quickly add wash to your PATH, you can move the binary to /usr/local/bin:

shell
sudo mv ~/wash/wash /usr/local/bin/

Clean up the source directory (optional):

shell
rm -rf ~/wash

Verify that wash is properly installed and check your version for 2.0.0-rc.6 with:

bash
wash -V

If wash is installed correctly, you will see a printout of all available commands and short descriptions for each. If you ever need more detail on a specific command or sub-command just run wash <command> --help.

Choose your language

wasmCloud supports building WebAssembly components from any language that supports the WASI P2 target, including Go, Rust, TypeScript, and others.

wash depends on your local language toolchain for your language of choice.

  • Choose the language you would like to use.
  • Install the toolchain or verify that you have the correct versions.

Install the Rust toolchain

Requirements:

On macOS or Ubuntu/Debian, you can use the official install script to download rustup, which will automatically install the Rust toolchain:

shell
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Once you've installed the Rust toolchain, use rustup to add the wasm32-wasip2 target:

shell
rustup target add wasm32-wasip2

Create a new component

Now that we've installed wash and our language toolchain, it's time to create a new component project.

In your terminal, run:

shell
wash new https://github.com/wasmCloud/wash.git --name hello --subfolder examples/quickstart/hello-rust

This command...

  • Creates a new project named hello...
  • Based on an example found in the wasmCloud/wash Git repository...
  • In the subfolder examples/quickstart/hello-rust.

Navigate to the hello project directory:

sh
cd hello

Start your developer loop

From our project directory, we'll run:

shell
wash dev

The wash dev command automatically builds your WebAssembly component and deploys it to a local wasmCloud environment. The terminal output should look like this:

text
INFO starting development session for project path="."
INFO building component path="."
INFO cargo build --target wasm32-wasip2 --color always completed in 0.14s
INFO HTTP server listening addr=0.0.0.0:8000
INFO development session started successfully
INFO listening for HTTP requests address=http://0.0.0.0:8000
INFO watching for file changes (press Ctrl+c to stop)...

By default, the application will run on our local port 8000. In a new terminal tab, we can curl our application:

shell
curl localhost:8000

The application should return:

text
Hello from Rust!

Make the application yours

Now we'll make a change to our code and see how the running application updates automatically.

The Rust code for our component is found in src/lib.rs.

Open the file in your code editor and change the "Hello" message on line 19. You might modify the message to say hello from WebAssembly, your own name, or whatever else you like.

rust
use wasmcloud_component::http;

struct Component;

http::export!(Component);

impl http::Server for Component {
    fn handle(
        _request: http::IncomingRequest,
    ) -> http::Result<http::Response<impl http::OutgoingBody>> {
        Ok(http::Response::new("Hello from Rust!\n")) 
        Ok(http::Response::new("Hello from Wasm!\n")) 
    }
}

Save the modified file. The wash dev automatically builds and deploys the updated component.

In the terminal, curl the application again:

shell
curl localhost:8000
text
Hello from Wasm!

Next steps

We installed wash, built our first component, and ran our application locally with wash dev.

In our next tutorial, we'll add pluggable, reusable capabilities like key-value storage to our application.