Skip to content

Commit c625ceb

Browse files
author
zach
authored
feat: add http plugin (#3)
1 parent de42aa1 commit c625ceb

4 files changed

Lines changed: 46 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ members = [
55
"store_credit",
66
"loop_forever",
77
"count_vowels_kvstore",
8+
"http"
89
]
910
resolver = "2"
1011

http/Cargo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "http"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
extism-pdk = {workspace = true}
10+
serde = {workspace = true}
11+
anyhow = {workspace = true}
12+
13+
[lib]
14+
crate_type = ["cdylib"]

http/src/lib.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use extism_pdk::*;
2+
3+
#[plugin_fn]
4+
pub unsafe fn http_get(Json(input): Json<HttpRequest>) -> FnResult<Vec<u8>> {
5+
let res = http::request::<()>(&input, None)?;
6+
let res = res.body();
7+
Ok(res)
8+
}
9+
10+
#[derive(serde::Serialize, serde::Deserialize)]
11+
struct HttpRequestWithBody {
12+
#[serde(flatten)]
13+
req: HttpRequest,
14+
data: String,
15+
}
16+
17+
#[plugin_fn]
18+
pub unsafe fn http_post(Json(input): Json<HttpRequestWithBody>) -> FnResult<Vec<u8>> {
19+
let res = http::request::<&str>(&input.req, Some(&input.data))?;
20+
let res = res.body();
21+
Ok(res)
22+
}

0 commit comments

Comments
 (0)