Skip to main content

Crate cufflink_fn

Crate cufflink_fn 

Source
Expand description

Write custom Cufflink handlers in Rust that compile to WASM.

This crate wraps the raw WASM host ABI so you write normal Rust code instead of pointer manipulation. Use it with cufflink services running in WASM mode.

§Quick Start

use cufflink_fn::prelude::*;

cufflink_fn::init!();

handler!(hello, |req: Request| {
    let name = req.body()["name"].as_str().unwrap_or("world");
    Response::json(&json!({"message": format!("Hello, {}!", name)}))
});

§Architecture

Organize your code in layers:

  • Handlers (thin) — parse request, call operation, return response
  • Operations (fat) — validation, business rules, orchestration
  • Repos (data) — pure SQL via db::query / db::execute

Modules§

config
Read service configuration values set via cufflink config set.
context
Runtime context provided by the platform: tenant identity, service identity, etc. Use these from client helpers that are called from inside handlers but don’t take a Request (e.g. shared cache wrappers).
db
Database access — run SQL queries against your service’s tables.
http
Make HTTP requests from inside your WASM handler.
image
Image transforms executed on the platform host.
log
Structured logging from inside your WASM handler.
migrate
Helpers for the optional on_migrate schema migration hook.
nats
Publish messages to NATS for event-driven communication.
prelude
Import everything you need to write handlers.
redis
Read and write values in Redis (backed by the platform’s Redis connection).
storage
Download files from S3-compatible object storage using the platform’s credentials.
util
Utility functions for common operations in WASM handlers.

Macros§

handler
Define a handler function.
init
Initialize the cufflink-fn runtime. Call this once at the top of your lib.rs.

Structs§

Auth
Authenticated user context, validated by the Cufflink platform.
JobContext
Context the platform attaches to a request when it was delivered via the long-running jobs runtime. Absent on direct HTTP invocations.
Request
An incoming HTTP request from the Cufflink platform.
Response
An HTTP response to return from your handler.