Skip to main content

Module routes

Module routes 

Source
Expand description

REST route handlers (deploy, invoke, metrics, healthz).

All handlers operate on a shared AppState containing in-memory registries of deployed functions and pending jobs, plus a shared TensorWasmMetrics registry and a TensorWasmExecutor. Wasm bytes are accepted as base64; the deploy path runs full wasmparser validation and stores the bytes (as Arc<[u8]> so concurrent invocations share a single allocation), and the synchronous invoke path drives tensor_wasm_exec::executor::TensorWasmExecutor to spawn, call _start / main, and terminate the instance. The async invoke-async path spawns the same flow on a Tokio task and records progress in the shared job registry for GET /jobs/{id} polling.

§Error envelope

Every error response carries the JSON envelope:

{ "error": { "kind": "<machine-readable>", "message": "<human-readable>" } }

kind strings are stable; message strings are not.

Structs§

ApiError
Error type returned by every fallible handler.
ApiErrorBody
Inner body of the JSON error envelope.
ApiErrorEnvelope
Top-level JSON error envelope as serialised to the wire: {"error":{"kind":..., "message":...}}.
AppState
Process-global state shared by every handler.
CreateFunctionRequest
Body of POST /functions.
CreateFunctionResponse
Response body of POST /functions.
FunctionRecord
A deployed function as held in memory by the API gateway.
InvokeRequest
Body of POST /functions/{id}/invoke and POST /functions/{id}/invoke-async.
JobRecord
An async-invocation record returned by GET /jobs/{id}.
SnapshotRestoreRequest
Body of POST /snapshot/restore.
SnapshotRestoreResponse
Response body of POST /snapshot/restore.
SnapshotSaveRequest
Body of POST /snapshot/save.
SnapshotSaveResponse
Response body of POST /snapshot/save.

Enums§

JobStatus
Status of an asynchronously dispatched invocation.

Constants§

BASE64_OFFLOAD_THRESHOLD
Body-size threshold above which base64 decoding is moved to tokio::task::spawn_blocking. Below this the inline decode is cheaper than the spawn handoff.
CHUNKED_MIME
Content-Type emitted by the chunked-transfer branch of invoke_function_stream when the request did not negotiate SSE.
MAX_FUNCTION_NAME_BYTES
Maximum byte-length of a tenant-supplied function name. Names are echoed back on every read of FunctionRecord, so an unchecked name field would let a caller pin arbitrarily many MiB of strings in the in-memory registry. 256 bytes is generous for any realistic display label while keeping the worst-case footprint of a million records under ~256 MiB.
MAX_INVOKE_ARGS
Maximum number of elements accepted in an InvokeRequest::args list.
MAX_JOB_RECORDS
SECURITY (unbounded jobs registry, MEDIUM): hard cap on the number of JobRecords retained in the in-memory jobs map.
MAX_OUTSTANDING_ASYNC_JOBS
SECURITY (async-invoke resource amplification, MEDIUM): ceiling on the number of concurrently-outstanding async invocation jobs.
SSE_MIME
Accept header value that selects the Server-Sent Events response shape on invoke_function_stream. Anything else (or absence) falls through to the raw chunked-transfer (application/octet-stream) branch.
STREAMING_CHANNEL_BUFFER
Channel buffer size for the gateway-side mpsc::channel::<Vec<u8>> paired with each /invoke-stream invocation.
WASM_MIN_HEADER_BYTES
Minimum length, in bytes, of a Wasm module: the 4-byte \0asm magic plus the 4-byte version field. Anything shorter cannot be a valid module.

Functions§

create_function
POST /functions — deploy a new Wasm module.
delete_function
DELETE /functions/{id} — remove a deployed function.
get_job
GET /jobs/{id} — poll an async invocation.
healthz
GET /healthz — liveness probe. Returns {"status":"ok"}.
invoke_function
POST /functions/{id}/invoke — synchronous invocation.
invoke_function_async
POST /functions/{id}/invoke-async — fire-and-forget invocation.
invoke_function_stream
POST /functions/{id}/invoke-stream — streaming invocation (roadmap feature #2; T34 wired this through end-to-end in v0.4).
metrics
GET /metrics — Prometheus text exposition.
snapshot_restore
POST /snapshot/restore — verify and decode a signed snapshot blob.
snapshot_save
POST /snapshot/save — capture a deployed function into a signed snapshot blob.

Type Aliases§

ApiResult
Convenience alias.