https://github.com/hyperlight-dev/hyperlight-wasm-http-example
https://github.com/hyperlight-dev/hyperlight-wasm-http-example
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/hyperlight-dev/hyperlight-wasm-http-example
- Owner: hyperlight-dev
- License: apache-2.0
- Created: 2025-08-26T17:46:58.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2026-04-09T15:10:09.000Z (3 months ago)
- Last Synced: 2026-04-09T17:09:00.196Z (3 months ago)
- Language: Rust
- Size: 210 KB
- Stars: 1
- Watchers: 0
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `hyperlight-wasm` http example
This is a minimal example of a
[hyperlight-wasm](https://github.com/hyperlight-dev/hyperlight-wasm)
host application. It implements just enough of the `wasi:http` api
to run the [sample_wasi_http_rust
server](https://github.com/bytecodealliance/sample-wasi-http-rust).
## Prerequisites
1. [Rust](https://www.rust-lang.org/tools/install), including the `x86_64-unknown-none` target (which may be installed via e.g. `rustup target add x86_64-unknown-none`)
2. `clang`
3. [`just`](https://github.com/casey/just) (optional, but recommended)
If you want to follow the manual build instructions, you will also need:
4. [`wasm-tools`](https://github.com/bytecodealliance/wasm-tools)
5. [`cargo-component`](https://github.com/bytecodealliance/cargo-component)
6. [`hyperlight-wasm-aot`](https://github.com/hyperlight-dev/hyperlight-wasm)
## Simple setup
### Building
```sh
# Install JS dependencies
npm install
```
```sh
just build
```
### Running
```sh
# Run Rust
just run-rust
# Run JS
just run-js
```
From another terminal, you can then test the server:
```sh
curl http://localhost:3000/
curl -w'\n' -d "hola mundo" http://127.0.0.1:3000/echo
curl -I -H "x-language: spanish" http://127.0.0.1:3000/echo-headers
# get the content of .gitignore from github.com/jprendes/hyperlight-wasm-http-example
curl -w'\n' http://127.0.0.1:3000/proxy
```
## Manual setup
### Building
Compile the WIT and set the environment variables used when building
(both the host and the guest):
```sh
wasm-tools component wit hyperlight.wit -w -o hyperlight-world.wasm
```
Build Rust:
```
cargo build
```
Build JS:
```
npm run build
```
### Running
Build the guest component:
```sh
cargo component build --release \
--manifest-path guest_rust/Cargo.toml \
--target-dir target
```
AOT compile it:
```sh
cargo install hyperlight-wasm-aot
hyperlight-wasm-aot compile --component \
target/wasm32-wasip1/release/sample_wasi_http_rust.wasm \
out/sample_wasi_http_rust.aot
```
You can then run the server:
Rust:
```sh
cargo run -- out/sample_wasi_http_rust.aot
```
JS:
```sh
cargo run -- out/sample-wasi-http-js.aot
```
## Try it yourself!
[GitHub codespaces](https://codespaces.new/hyperlight-dev/hyperlight-wasm-http-example)