Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: use remote repos in examples and docs. Add a README.md to examples #160

Merged
merged 1 commit into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions docs/docs/get-started/how-it-works.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ Wasm Workers is built around two main ideas:

Based on these two principles, the server performs the following tasks:

* Identify `.wasm` modules in the given folder
* Associate a HTTP route to every module
* Create a Key / Value in-memory store if required
* Initialize the [Wasmtime](https://wasmtime.dev/) runtime
* Compile the different modules and initialize them
* Spin an HTTP server to start serving the requests
* Identify `.wasm` modules and any other supported languages (like `.js` and `.py`) in the given folder.
* Associate a HTTP route to every module.
* Create a Key / Value in-memory store if required.
* Initialize the [Wasmtime](https://wasmtime.dev/) runtime..
* Start a HTTP server to start serving the requests.

## Convention over configuration

Expand All @@ -40,4 +39,4 @@ version = "1"
namespace = "counter"
```

These files are only required to enable extra features for your workers.
These files are only required to enable extra features for your workers.
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,21 @@
sidebar_position: 1
---

import Diagram from '../../src/pages/diagram.svg';

# Introduction

## What's Wasm Workers Server?

Wasm Workers Server is a framework that allows you to develop and run serverless applications using a lightweight construct called "workers", explained later in the document. The server itself is implemented as a self-contained binary that routes HTTP requests to a WebAssembly runtime that hosts the workers. It looks for `.wasm` and other compatible modules (like JavaScript files) in the given folder and associate HTTP endpoints based on their path:

```bash
$ wws --help
Usage: wws [OPTIONS] [PATH] [COMMAND]

Commands:
runtimes Manage the language runtimes in your project
help Print this message or the help of the given subcommand(s)

Arguments:
[PATH] Folder to read WebAssembly modules from [default: .]

Options:
--host <HOSTNAME> Hostname to initiate the server [default: 127.0.0.1]
-p, --port <PORT> Port to initiate the server [default: 8080]
--prefix <PREFIX> Prepend the given path to all URLs [default: ]
-h, --help Print help
-V, --version Print version
```

You don't need to configure anything by default. Just drop your workers in a folder and run the project to get an HTTP server and start serving requests 🚀.
Wasm Workers Server is a framework that allows you to develop and run serverless applications using a lightweight construct called "workers", explained later in the document. The server itself is implemented as a self-contained binary that routes HTTP requests to a WebAssembly runtime that hosts the workers. It looks for `.wasm` and other compatible modules (like [JavaScript](../languages/javascript.md) and [Python](../languages//python.md) files) in the given folder and associate HTTP endpoints based on their path:

```bash
$ curl http://localhost:8080/api/hello
<p align="center">
<Diagram />
</p>

Hello Wasm!
```
You don't need to configure anything by default. Just provide a project location to `wws` and it will identify the workers and start serving requests 🚀.

That's all! Now it's your turn [to download and start using Wasm Workers Server](./quickstart.md).
Now it's your turn [to download and start using Wasm Workers Server](./quickstart.md).

## What's a worker?

Expand All @@ -57,4 +38,4 @@ Wasm Workers Server is a lightweight implementation of a Worker platform that ai

It aims for compatibility and follows an ongoing specification that different companies are working under the name of [WinterCG](https://wintercg.org/faq). This working group aims to create a common API for using Web Platform APIs like workers outside of the browser.

Many of the platforms mentioned earlier follow a similar approach, so any code you write for Wasm Workers Server can be moved to those platforms easily (or the other way around!). Remember that our focus with wws is simplicity and compatibility. Since this is a growing ecosystem, we want you to start quickly and move wherever you need.
Many of the platforms mentioned earlier follow a similar approach, so any code you write for Wasm Workers Server can be moved to those platforms easily (or the other way around!). Remember that our focus with wws is simplicity and compatibility. Since this is a growing ecosystem, we want you to start quickly and move wherever you need.
43 changes: 25 additions & 18 deletions docs/docs/get-started/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ curl -fsSL https://workers.wasmlabs.dev/install | bash
Now, you can check the different commands and options:

```bash
wws --help
$ wws --help
A WebAssembly framework to develop and run serverless applications anywhere

Usage: wws [OPTIONS] [PATH] [COMMAND]

Expand All @@ -24,32 +25,38 @@ Commands:
help Print this message or the help of the given subcommand(s)

Arguments:
[PATH] Folder to read WebAssembly modules from [default: .]
[PATH] Location of the wws project. It could be a local folder or a git repository [default: .]

Options:
--host <HOSTNAME> Hostname to initiate the server [default: 127.0.0.1]
-p, --port <PORT> Port to initiate the server [default: 8080]
--prefix <PREFIX> Prepend the given path to all URLs [default: ]
-h, --help Print help information
-V, --version Print version information
--host <HOSTNAME> Hostname to initiate the server [default: 127.0.0.1]
-p, --port <PORT> Port to initiate the server [default: 8080]
--prefix <PREFIX> Prepend the given path to all URLs [default: ]
--ignore <IGNORE> Patterns to ignore when looking for worker files [default: ]
-i, --install-runtimes Install missing runtimes automatically
--git-commit <GIT_COMMIT> Set the commit when using a git repository as project
--git-tag <GIT_TAG> Set the tag when using a git repository as project
--git-branch <GIT_BRANCH> Set the branch when using a git repository as project
--git-folder <GIT_FOLDER> Change the directory when using a git repository as project
--enable-panel Enable the administration panel
-h, --help Print help
-V, --version Print version
```

You can download some of our example `.js` modules:
You can pass a remote location, like a git repository, to `wws`. To try it, let's run one of the `js-basic` example from the Wasm Workers Server repository:

```bash
curl https://raw.githubusercontent.com/vmware-labs/wasm-workers-server/main/examples/js-basic/index.js \
-o ./index.js
wws https://github.com/vmware-labs/wasm-workers-server.git -i --git-folder "examples/js-basic"
```

Finally, you can run wws and check the response from the worker:
It automatically clones the git repository and loads the workers from the given folder (`examples/js-basic`):

```bash
wws .

⚙️ Loading routes from: ./examples
🗺 Detected routes:
```shell
⚙️ Preparing the project from: https://github.com/vmware-labs/wasm-workers-server.git
⚙️ Loading routes from: /tmp/dd21e3cd6d0f515301e1c7070e562af06074d9e8d10566179f97dba47e74cec9/examples/js-basic
Loading workers from 1 routes...
✅ Workers loaded in 108.82825ms.
- http://127.0.0.1:8080/
=> index.js (name: default)
=> /tmp/dd21e3cd6d0f515301e1c7070e562af06074d9e8d10566179f97dba47e74cec9/examples/js-basic/index.js
🚀 Start serving requests at http://127.0.0.1:8080
```

Expand All @@ -65,4 +72,4 @@ Now you got the taste of Wasm Workers, it's time to create your first worker:
* [Create your first Ruby worker](../languages/ruby.md)
* [Create your first Go worker](../languages/go.md)

And if you are curious, here you have a guide about [how it works](./how-it-works.md).
And if you are curious, here you have a guide about [how it works](./how-it-works.md).
18 changes: 17 additions & 1 deletion docs/docs/languages/javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ sidebar_position: 1

Workers based on JavaScript work out of the box with Wasm Workers Server. The server integrates a JavaScript interpreter compiled into a WebAssembly module. Currently, the interpreter we support is [quickjs](https://bellard.org/quickjs/) and we are working on adding new ones.

## Run a JavaScript example

1. Download `wws`:

```bash
curl -fsSL https://workers.wasmlabs.dev/install | bash
```

2. Run the [js-basic]((https://github.com/vmware-labs/wasm-workers-server/tree/main/examples/js-basic)) example from the Wasm Workers Server's repository:

```bash
wws https://github.com/vmware-labs/wasm-workers-server.git -i --git-folder "examples/js-basic"
```

3. Access to <a href="http://localhost:8080/" target="_blank">http://localhost:8080</a>.

## Your first JavaScript worker

JavaScript workers are based on the [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) / [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) objects from the Web Fetch API. Your worker needs to listen to the `fetch` event, which will include an associated `Request` object. The worker function will receive the request and generate a `Response` object to reply to the request.
Expand Down Expand Up @@ -186,4 +202,4 @@ If you prefer, you can configure the environment variable value dynamically by f
* [Basic](https://github.com/vmware-labs/wasm-workers-server/tree/main/examples/js-basic/)
* [JSON](https://github.com/vmware-labs/wasm-workers-server/tree/main/examples/js-json/)
* [Redirect](https://github.com/vmware-labs/wasm-workers-server/tree/main/examples/js-redirect/)
* [Tic Tac Toe](https://github.com/vmware-labs/wasm-workers-server/tree/main/examples/js-tictactoe/)
* [Tic Tac Toe](https://github.com/vmware-labs/wasm-workers-server/tree/main/examples/js-tictactoe/)
20 changes: 18 additions & 2 deletions docs/docs/languages/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,25 @@ sidebar_position: 3

The [Python](https://www.python.org/) interpreter is not embedded in Wasm Workers Server. To create workers based on this language, you first need to install a Python runtime.

Fortunately, we provide precompiled `python.wasm` modules in our [WebAssembly Language Runtimes](https://github.com/vmware-labs/webassembly-language-runtimes/) project, so the installation is simple:
Fortunately, we provide precompiled `python.wasm` modules in our [WebAssembly Language Runtimes](https://github.com/vmware-labs/webassembly-language-runtimes/) project, so the installation is simple.

## Installation
## Run a Python example

1. Download `wws`:

```bash
curl -fsSL https://workers.wasmlabs.dev/install | bash
```

2. Run the [python-basic]((https://github.com/vmware-labs/wasm-workers-server/tree/main/examples/python-basic)) example from the Wasm Workers Server's repository. The `-i` flag will install the Python runtime automatically.

```bash
wws https://github.com/vmware-labs/wasm-workers-server.git -i --git-folder "examples/python-basic"
```

3. Access to <a href="http://localhost:8080/" target="_blank">http://localhost:8080</a>.

## Python runtime Installation

To install the Python Wasm module, run the following command:

Expand Down
22 changes: 19 additions & 3 deletions docs/docs/languages/ruby.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,25 @@ sidebar_position: 4

The [Ruby](https://www.ruby-lang.org/) interpreter is not embedded in Wasm Workers Server. To create workers based on this language, you first need to install a Ruby runtime.

Fortunately, we provide precompiled `ruby.wasm` modules in our [WebAssembly Language Runtimes](https://github.com/vmware-labs/webassembly-language-runtimes/) project, so the installation is simple:
Fortunately, we provide precompiled `ruby.wasm` modules in our [WebAssembly Language Runtimes](https://github.com/vmware-labs/webassembly-language-runtimes/) project, so the installation is simple.

## Installation
## Run a Ruby example

1. Download `wws`:

```bash
curl -fsSL https://workers.wasmlabs.dev/install | bash
```

2. Run the [ruby-basic](https://github.com/vmware-labs/wasm-workers-server/tree/main/examples/ruby-basic) example from the Wasm Workers Server's repository. The `-i` flag will install the Ruby runtime automatically.

```bash
wws https://github.com/vmware-labs/wasm-workers-server.git -i --git-folder "examples/ruby-basic"
```

3. Access to <a href="http://localhost:8080/" target="_blank">http://localhost:8080</a>.

## Ruby runtime installation

To install the Ruby Wasm module, run the following command:

Expand Down Expand Up @@ -170,4 +186,4 @@ If you prefer, you can configure the environment variable value dynamically by f

* [Basic](https://github.com/vmware-labs/wasm-workers-server/tree/main/examples/ruby-basic/)
* [Key / Value](https://github.com/vmware-labs/wasm-workers-server/tree/main/examples/ruby-kv/)
* [Environment variables](https://github.com/vmware-labs/wasm-workers-server/tree/main/examples/ruby-envs/)
* [Environment variables](https://github.com/vmware-labs/wasm-workers-server/tree/main/examples/ruby-envs/)
6 changes: 3 additions & 3 deletions examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ rust-params:
cargo build --target wasm32-wasi --release && \
mv target/wasm32-wasi/release/rust-params.wasm "./[id].wasm"

pdf-create:
cd pdf-create && \
rust-pdf-create:
cd rust-pdf-create && \
cargo build --target wasm32-wasi --release && \
mv target/wasm32-wasi/release/pdf-create.wasm ./index.wasm
mv target/wasm32-wasi/release/rust-pdf-create.wasm ./index.wasm

all: rust-basic rust-kv rust-params
17 changes: 11 additions & 6 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# Wasm Workers Server examples

This folder includes different handlers. All of them are based on other projects as we aim to create a server that is compatible with different providers.
This folder includes several workers examples. They are written in different languages and showcases all the features from Wasm Workers Server.

## Build
Every example includes a `README.md` file with all the instructions.

### JavaScript workers
## Documentation

Wasm Workers Server includes a `QuickJS` interpreter. JavaScript workers are automatically compatible and you don't need to compile them to WebAssembly, although they will run in it.
* [Quickstart](https://workers.wasmlabs.dev/docs/get-started/quickstart)
* [Features](https://workers.wasmlabs.dev/docs/category/features)

### Rust workers
### Language resources

For Rust workers, you need to use our `wasm-workers-server-kit` crate. This folder contains several examples of its usage.
* [JavaScript documentation](https://workers.wasmlabs.dev/docs/languages/javascript)
* [Rust documentation](https://workers.wasmlabs.dev/docs/languages/rust)
* [Python documentation](https://workers.wasmlabs.dev/docs/languages/python)
* [Ruby documentation](https://workers.wasmlabs.dev/docs/languages/ruby)
* [Go documentation](https://workers.wasmlabs.dev/docs/languages/go)
31 changes: 31 additions & 0 deletions examples/go-basic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Go basic example

Compile a Go worker to WebAssembly and run it in Wasm Workers Server.

## Prerequisites

* Wasm Workers Server (wws):

```shell-session
curl -fsSL https://workers.wasmlabs.dev/install | bash
```

* [Go](https://go.dev/)
* [TinyGo](https://tinygo.org/getting-started/install/)

## Build

```shell-session
tinygo build -o index.wasm -target wasi main.go
```

## Run

```shell-session
wws .
```

## Resources

* [Go documentation](https://workers.wasmlabs.dev/docs/languages/go)
* [Announcing Go support for Wasm Workers Server](https://wasmlabs.dev/articles/go-support-on-wasm-workers-server/)
32 changes: 32 additions & 0 deletions examples/go-envs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Go environment variables example

Compile a Go worker to WebAssembly and run it in Wasm Workers Server.

## Prerequisites

* Wasm Workers Server (wws):

```shell-session
curl -fsSL https://workers.wasmlabs.dev/install | bash
```

* [Go](https://go.dev/)
* [TinyGo](https://tinygo.org/getting-started/install/)

## Build

```shell-session
tinygo build -o envs.wasm -target wasi envs.go
```

## Run

```shell-session
wws .
```

## Resources

* [Environment variables](https://workers.wasmlabs.dev/docs/features/environment-variables)
* [Go documentation](https://workers.wasmlabs.dev/docs/languages/go)
* [Announcing Go support for Wasm Workers Server](https://wasmlabs.dev/articles/go-support-on-wasm-workers-server/)
32 changes: 32 additions & 0 deletions examples/go-kv/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Go Key / Value store example

Compile a Go worker to WebAssembly and run it in Wasm Workers Server.

## Prerequisites

* Wasm Workers Server (wws):

```shell-session
curl -fsSL https://workers.wasmlabs.dev/install | bash
```

* [Go](https://go.dev/)
* [TinyGo](https://tinygo.org/getting-started/install/)

## Build

```shell-session
tinygo build -o counter.wasm -target wasi counter.go
```

## Run

```shell-session
wws .
```

## Resources

* [Key / Value store](https://workers.wasmlabs.dev/docs/features/key-value)
* [Go documentation](https://workers.wasmlabs.dev/docs/languages/go)
* [Announcing Go support for Wasm Workers Server](https://wasmlabs.dev/articles/go-support-on-wasm-workers-server/)
Loading