Skip to content

Commit

Permalink
feat: add new fetch bindings to the rust kit (#171)
Browse files Browse the repository at this point in the history
* feat: add new fetch bindings to the rust kit

* docs: pin the Rust examples to the latest version branch

* feat: allow passing a Vec<u8> as body when making requests from a worker

* docs: add a clarification about how rust-fetch example is retrieving the data
  • Loading branch information
Angelmmiguel authored Jul 6, 2023
1 parent bcbf473 commit e7f389e
Show file tree
Hide file tree
Showing 12 changed files with 692 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ members = [
exclude = [
"examples/pdf-create",
"examples/rust-basic",
"examples/rust-fetch",
"examples/rust-kv",
"examples/rust-params"
]
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/languages/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ In this example, the worker will get a request and print all the related informa
[dependencies]
anyhow = "1.0.63"
wasm-workers-rs = { git = "https://github.com/vmware-labs/wasm-workers-server/" }
wasm-workers-rs = { git = "https://github.com/vmware-labs/wasm-workers-server/", branch = "v1.3" }
```
1. Add the `reply` function to the `src/main.rs` file. You will need to import the required resources from the `wasm-workers-rs` crate and use the `worker` macro:
Expand Down Expand Up @@ -136,7 +136,7 @@ To add a KV store to your worker, follow these steps:
[dependencies]
anyhow = "1.0.63"
wasm-workers-rs = { git = "https://github.com/vmware-labs/wasm-workers-server/" }
wasm-workers-rs = { git = "https://github.com/vmware-labs/wasm-workers-server/", branch = "v1.3" }
```
1. Add the `reply` function to the `src/main.rs` file. You will need to import the required resources from the `wasm-workers-rs` crate and use the `worker` macro. In this case, we will add a new attribute to the `worker` macro called `cache` and update the function signature:
Expand Down Expand Up @@ -317,4 +317,4 @@ If you prefer, you can configure the environment variable value dynamically by f
## Other examples
* [Basic](https://github.com/vmware-labs/wasm-workers-server/tree/main/examples/rust-basic)
* [Counter](https://github.com/vmware-labs/wasm-workers-server/tree/main/examples/rust-kv)
* [Counter](https://github.com/vmware-labs/wasm-workers-server/tree/main/examples/rust-kv)
7 changes: 6 additions & 1 deletion examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ rust-basic:
cargo build --target wasm32-wasi --release && \
cp target/wasm32-wasi/release/rust-basic.wasm ./basic.wasm

rust-fetch:
cd rust-fetch && \
cargo build --target wasm32-wasi --release && \
cp target/wasm32-wasi/release/rust-fetch.wasm ./index.wasm

rust-kv:
cd rust-kv && \
cargo build --target wasm32-wasi --release && \
Expand All @@ -20,4 +25,4 @@ rust-pdf-create:
cargo build --target wasm32-wasi --release && \
mv target/wasm32-wasi/release/rust-pdf-create.wasm ./index.wasm

all: rust-basic rust-kv rust-params
all: rust-basic rust-fetch rust-kv rust-params
166 changes: 164 additions & 2 deletions examples/rust-basic/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e7f389e

Please sign in to comment.