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.
- ApiError
Body - Inner body of the JSON error envelope.
- ApiError
Envelope - Top-level JSON error envelope as serialised to the wire:
{"error":{"kind":..., "message":...}}. - AppState
- Process-global state shared by every handler.
- Create
Function Request - Body of
POST /functions. - Create
Function Response - Response body of
POST /functions. - Function
Record - A deployed function as held in memory by the API gateway.
- Invoke
Request - Body of
POST /functions/{id}/invokeandPOST /functions/{id}/invoke-async. - JobRecord
- An async-invocation record returned by
GET /jobs/{id}. - Snapshot
Restore Request - Body of
POST /snapshot/restore. - Snapshot
Restore Response - Response body of
POST /snapshot/restore. - Snapshot
Save Request - Body of
POST /snapshot/save. - Snapshot
Save Response - 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_streamwhen 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::argslist. - MAX_
JOB_ RECORDS - SECURITY (unbounded
jobsregistry, MEDIUM): hard cap on the number ofJobRecords retained in the in-memoryjobsmap. - MAX_
OUTSTANDING_ ASYNC_ JOBS - SECURITY (async-invoke resource amplification, MEDIUM): ceiling on the number of concurrently-outstanding async invocation jobs.
- SSE_
MIME Acceptheader value that selects the Server-Sent Events response shape oninvoke_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-streaminvocation. - WASM_
MIN_ HEADER_ BYTES - Minimum length, in bytes, of a Wasm module: the 4-byte
\0asmmagic 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.