| Crates.io | extension_api |
| lib.rs | extension_api |
| version | 0.0.8 |
| created_at | 2024-12-01 12:57:18.875214+00 |
| updated_at | 2025-06-08 11:46:13.132287+00 |
| description | 自定义wasm plugin 扩展api |
| homepage | |
| repository | https://github.com/workoss/wasm-extension |
| max_upload_size | |
| id | 1467424 |
| size | 24,982 |
依赖 extension_api
add this to your Cargo.toml:
[dependencies]
extension_api = "0.0.8"
实现 api
cargo create --lib demo_plugin
src/lib.rs
use extension_api::{
register_plugin,
wit::{
get_settings,
workoss::extension::{
extension_http::{fetch, HttpRequest},
platform::current_platform,
},
PluginInput, PluginOutput,
},
Plugin,
};
struct DemoPlugin;
impl Plugin for DemoPlugin {
fn new() -> Self
where
Self: Sized,
{
Self
}
fn run_plugin(&self, input: PluginInput) -> Result<PluginOutput, String> {
let (os, arch) = current_platform()?;
println!("host os:{os:?},arch:{arch:?}");
let input = String::from_utf8(input.body.unwrap()).unwrap();
println!("demo plugin input:{:#?}", input);
let settings = get_settings(Some("plugin_key"))?;
println!("settings: {:#?}", settings);
let req = HttpRequest::builder()
.method(extension_api::wit::workoss::extension::http_client::HttpMethod::Get)
.url("https://www.baidu.com")
.build()?;
let resp = fetch(&req).map_err(|e| format!("{e:?}"))?;
let body = String::from_utf8(resp.body).unwrap();
println!("resp body:{:?}", &body);
Ok(PluginOutput {
body: Some(body.into_bytes()),
mime_type: extension_api::wit::MimeType::Json,
})
}
}
register_plugin!(DemoPlugin);