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

Add https example #4

Merged
merged 2 commits into from
Nov 24, 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
18 changes: 14 additions & 4 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,23 @@ jobs:
- name: Install WasmEdge
run: |
VERSION=0.13.5
curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | sudo bash -s -- --version=$VERSION -p /usr/local
curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | sudo bash -s -- --version=$VERSION --plugins=wasmedge_rustls -p /usr/local

- name: Client example
run: |
cargo build --target wasm32-wasi --release
wasmedgec target/wasm32-wasi/release/wasmedge_reqwest_demo.wasm wasmedge_reqwest_demo.wasm
resp=$(wasmedge wasmedge_reqwest_demo.wasm 2>&1)
wasmedgec target/wasm32-wasi/release/http.wasm http.wasm
wasmedgec target/wasm32-wasi/release/https.wasm https.wasm
resp=$(wasmedge http.wasm 2>&1)
echo "$resp"
if [[ $resp == *"WasmEdge"* ]]; then
echo -e "Execution Success!"
else
echo -e "Execution Fail!"
exit 1
fi

resp=$(wasmedge https.wasm 2>&1)
echo "$resp"
if [[ $resp == *"WasmEdge"* ]]; then
echo -e "Execution Success!"
Expand Down
12 changes: 10 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@ version = "0.1.0"
edition = "2021"

[dependencies]
reqwest_wasi = "0.11"
tokio_wasi = { version = "1", features = ["rt", "macros", "net", "time"]}
reqwest_wasi = { version = "0.11", features = ["wasmedge-tls"] }
tokio_wasi = { version = "1", features = ["rt", "macros", "net", "time"] }

[[bin]]
name = "http"
path = "src/http.rs"

[[bin]]
name = "https"
path = "src/https.rs"
File renamed without changes.
37 changes: 37 additions & 0 deletions src/https.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), reqwest::Error> {
// Some simple CLI args requirements...
let url = "https://eu.httpbin.org/get?msg=WasmEdge";

eprintln!("Fetching {:?}...", url);

let res = reqwest::get(url).await?;

eprintln!("Response: {:?} {}", res.version(), res.status());
eprintln!("Headers: {:#?}\n", res.headers());

let body = res.text().await?;
println!("GET: {}", body);

let client = reqwest::Client::new();

let res = client
.post("https://eu.httpbin.org/post")
.body("msg=WasmEdge")
.send()
.await?;
let body = res.text().await?;

println!("POST: {}", body);

let res = client
.put("https://eu.httpbin.org/put")
.body("msg=WasmEdge")
.send()
.await?;
let body = res.text().await?;

println!("PUT: {}", body);

Ok(())
}
Loading