Expand description
§FastEdge Rust SDK
A comprehensive toolkit for building high-performance edge computing applications using WebAssembly.
§Overview
The fastedge crate provides two runtime models:
-
WebAssembly Component Model (default): Modern WebAssembly component model using WIT (WebAssembly Interface Types) for type-safe interfaces. This API resides in the root of the
fastedgecrate’s namespace. -
ProxyWasm API: Compatibility layer for ProxyWasm environments (Envoy, etc.). Available via the
fastedge::proxywasmmodule when theproxywasmfeature is enabled.
§Features
- HTTP Request Handling: Process incoming HTTP requests at the edge
- Outbound HTTP Client: Make HTTP requests to backend services via
send_request - Key-Value Storage: Persistent storage with advanced operations (scan, sorted sets, bloom filters)
- Secret Management: Secure access to encrypted secrets with time-based retrieval
- Dictionary: Fast read-only key-value lookups for configuration
- WASI-NN: Machine learning inference support via
wasi_nn
§Quick Start
Add to your Cargo.toml:
[dependencies]
fastedge = "0.3"
anyhow = "1.0"
[lib]
crate-type = ["cdylib"]Create a simple HTTP handler:
use anyhow::Result;
use fastedge::body::Body;
use fastedge::http::{Request, Response, StatusCode};
#[fastedge::http]
fn main(_req: Request<Body>) -> Result<Response<Body>> {
Response::builder()
.status(StatusCode::OK)
.body(Body::from("Hello, FastEdge!"))
.map_err(Into::into)
}Build for WebAssembly:
rustup target add wasm32-wasip1
cargo build --target wasm32-wasip1 --release§Feature Flags
proxywasm(default): Enable ProxyWasm compatibility layerjson: Enable JSON body support viaserde_json
§Examples
§Making HTTP Requests
use anyhow::Result;
use fastedge::body::Body;
use fastedge::http::{Method, Request, Response, StatusCode};
#[fastedge::http]
fn main(_req: Request<Body>) -> Result<Response<Body>> {
// Create a request to a backend service
let backend_request = Request::builder()
.method(Method::GET)
.uri("https://api.example.com/data")
.header("User-Agent", "FastEdge/1.0")
.body(Body::empty())?;
// Send the request
let backend_response = fastedge::send_request(backend_request)?;
// Return the response
Response::builder()
.status(StatusCode::OK)
.body(backend_response.into_body())
.map_err(Into::into)
}§Using Key-Value Storage
use anyhow::Result;
use fastedge::body::Body;
use fastedge::http::{Request, Response, StatusCode};
use fastedge::key_value::Store;
#[fastedge::http]
fn main(_req: Request<Body>) -> Result<Response<Body>> {
// Open a key-value store
let store = Store::open("my-store")?;
// Get a value
if let Some(value) = store.get("user:123")? {
return Response::builder()
.status(StatusCode::OK)
.body(Body::from(value))
.map_err(Into::into);
}
Response::builder()
.status(StatusCode::NOT_FOUND)
.body(Body::empty())
.map_err(Into::into)
}§Accessing Secrets
use anyhow::Result;
use fastedge::body::Body;
use fastedge::http::{Request, Response, StatusCode};
use fastedge::secret;
#[fastedge::http]
fn main(_req: Request<Body>) -> Result<Response<Body>> {
// Get a secret value
match secret::get("API_KEY")? {
Some(api_key) => {
// Use the API key
let key = String::from_utf8_lossy(&api_key);
Response::builder()
.status(StatusCode::OK)
.body(Body::from("Secret retrieved"))
.map_err(Into::into)
}
None => {
Response::builder()
.status(StatusCode::NOT_FOUND)
.body(Body::from("Secret not found"))
.map_err(Into::into)
}
}
}Re-exports§
pub extern crate http;
Modules§
- body
- HTTP request and response body types.
- dictionary
- Fast read-only key-value dictionary for configuration.
- exports
- gcore
- key_
value - Persistent key-value storage with advanced data structures.
- proxywasm
- FastEdge ProxyWasm module extension ProxyWasm compatibility layer for FastEdge.
- secret
- Secure access to encrypted secrets and credentials.
- utils
- FastEdge-specific utility functions for diagnostics and statistics.
- wasi_nn
Macros§
- export
- Generates
#[unsafe(no_mangle)]functions to export the specified type as the root implementation of all generated traits.
Enums§
- Error
- Errors that can occur when using the FastEdge SDK.
Functions§
- send_
request - Sends an HTTP request to a backend service.
Attribute Macros§
- http
- Marks a function as the HTTP request handler for a FastEdge application.