Skip to content

Commit

Permalink
Merge pull request WasmEdge#4 from second-state/ci/https
Browse files Browse the repository at this point in the history
  • Loading branch information
juntao committed Nov 24, 2023
2 parents 19a88b0 + bd4b647 commit 2f02f82
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 6 deletions.
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(())
}

0 comments on commit 2f02f82

Please sign in to comment.