Expand description
§Node-App SDK for Rust
Build native Node-App plugins as shared libraries (cdylib) with a
safe, ergonomic Rust API. The SDK targets the Node Host API v1
(the canonical C header is core/host-abi-v1/include/node-host-api-v1.h
in the host repository).
§What this crate provides
- The
NodeApptrait — implement it on your plugin type to get HTTP, event, and capability handling. - The
declare_node_app!macro — generates all FFI boilerplate (vtable, panic guards, JSON serialization) from your trait impl. - Helpers for talking to the host:
log,invoke_capability,publish_event,get_config,get_storage,set_storage. - Distributed-trace propagation across capability invocations
(thread-local span context — see [
CurrentTrace]). - Hard limits matching the host:
MAX_CAPABILITY_RESPONSE_SIZE(16 MiB),MAX_EVENT_NAME_LEN(256 B),MAX_EVENT_DATA_LEN(64 KiB).
§Stability
This crate is published as 1.0.1-experimental. The trait surface
and the underlying C ABI are FROZEN for the v1 series, but breaking
changes between 1.0.x-experimental releases are possible until at
least two first-party packages have proven the surface in production.
Pin to an exact version in Cargo.toml.
§Quick start
# Cargo.toml
[lib]
crate-type = ["cdylib"]
[dependencies]
node-app-sdk-rust = "1.0.1-experimental"
serde_json = "1.0"use node_app_sdk_rust::*;
#[derive(Default)]
pub struct MyApp;
impl NodeApp for MyApp {
fn metadata() -> NodeAppInfo {
NodeAppInfo {
name: "my-app".into(),
version: "0.1.0".into(),
author: "Me".into(),
description: "Hello-world Node-App".into(),
capabilities: vec!["http_handler".into()],
}
}
fn handle_request(&self, _req: AppRequest) -> Result<AppResponse, NodeAppError> {
Ok(AppResponse {
status: 200,
headers: Default::default(),
body: serde_json::json!({ "hello": "world" }),
})
}
}
declare_node_app!(MyApp);Build with cargo build --release; the resulting shared library plus a
manifest.json is installed into the host’s app directory.
§Calling host capabilities
Use invoke_capability to call any capability registered with the
host’s capability router (e.g. core.storage.get,
core.lightning.payment.send):
use node_app_sdk_rust::{invoke_capability, CapabilityRequest};
let response = invoke_capability(&CapabilityRequest {
id: "req-1".into(),
capability: "core.storage.get".into(),
payload: serde_json::json!({ "key": "user_pref" }),
caller_node_id: None,
trace_id: None,
span_id: None,
parent_span_id: None,
trace_depth: None,
})?;Trace context (trace_id, span_id, trace_depth) is propagated
automatically when invoking from inside handle_capability — you do
not need to thread it manually.
§Publishing events
use node_app_sdk_rust::publish_event;
publish_event(
"my-app.something_happened",
&serde_json::json!({ "user_id": 42 }),
)?;Event names must be namespaced with the app name (my-app.*); the
host rejects un-namespaced events.
Modules§
Macros§
- declare_
node_ app - Generate all FFI boilerplate for a
NodeAppimplementation. - log_
debug - Log a DEBUG-level message using
format!-style arguments. - log_
error - Log an ERROR-level message using
format!-style arguments. - log_
info - Log an INFO-level message using
format!-style arguments. - log_
trace - Log a TRACE-level message using
format!-style arguments. - log_
warn - Log a WARN-level message using
format!-style arguments.
Structs§
- AppEvent
- Domain event forwarded to apps
- AppRequest
- HTTP request forwarded to an app
- AppResponse
- HTTP response from an app
- Capabilities
- Capability flags declaring what an app can do
- Capability
Example - An example request payload for a capability.
- Capability
Request - A service capability request dispatched to a provider app. Used for both FFI (serialized as JSON bytes) and IPC (serialized as JSON).
- Capability
Response - Response from a provider app after handling a capability request.
- FfiResult
- Result type returned by FFI functions
- Node
AppContext - Host context provided to native apps.
- Node
AppInfo - App metadata returned during initialization
- Node
AppMetadata - App metadata returned by the entry point function
- Node
AppV Table - VTable of function pointers for app operations.
Returned by the
_node_app_entrysymbol. - Provided
Capability - Declaration of a service capability that an app provides. Used in app manifests and registration APIs.
Enums§
- Node
AppError - Error type returned by app operations.
Constants§
- API_
VERSION - API version for compatibility checking between host and native apps. Host and app must have matching API_VERSION to load successfully.
- MAX_
CAPABILITY_ RESPONSE_ SIZE - Maximum response size for capability handlers (16 MiB).
- MAX_
EVENT_ DATA_ LEN - Maximum event data length in bytes (64 KiB).
- MAX_
EVENT_ NAME_ LEN - Maximum event name length in bytes (256).
Traits§
- NodeApp
- Trait implemented by node-app plugins.
Functions§
- get_
config - Get a configuration value from the host by key.
- get_
storage - Get a storage value by key, scoped to this app.
- invoke_
capability - Invoke a capability on the host via the capability router.
- log
- Log a message to the host using the stored context.
- publish_
event - Publish a domain event to the host event bus.
- set_
storage - Set a storage value scoped to this app.