@scramjet/rest-api2
v2.0.0
Published
Scramjet Transform Hub v2 REST API contracts and common client.
Readme
@scramjet/rest-api2
⚠ Experimental: This package is experimental. Its API may change without notice in minor or patch releases.
v2 REST API contracts, shared handlerless route definitions, Zod schemas, and a manifest-backed common client for Scramjet Transform Hub.
The @scramjet/rest-api2 package provides the canonical API v2 type contracts and client infrastructure. Its scope includes:
- Type definitions — v2 request/response payloads, generic structures, and operation identifiers under the
RestAPI2namespace. - Route definitions —
RestAPI2RouteSetsandRestAPI2Routesfor building manifests, including the pre-builtRestAPI2Routesrouter tree for root, space, hub, and instance nodes. - Generic client —
createRestAPI2Client()using aRouteManifestandApiClientTransport. - Fluent clients —
createRootClient,createSpaceClient,createHubClient,createInstanceClient, andcreateFluentClientFromRouteTreeNodefor typed traversal of the route tree. - Transports —
createHttpClientTransportfor HTTP access andcreateVerser2ClientTransportfor verser2 protocol access.
When to use
Use @scramjet/rest-api2 when you need to interact with Transform Hub programmatically using the current v2 API contract. This package is the primary API client library for new integrations. It is transport-agnostic and can be used in Node.js and browser environments (when using the HTTP transport with a fetch polyfill).
For existing integrations using the legacy v1 API, see @scramjet/api-client.
Quick start
import {
RestAPI2Routes,
createHttpClientTransport,
createRestAPI2Client,
createRootClient
} from "@scramjet/rest-api2";
const manifest = RestAPI2Routes.root
.router("/api/v2")
.collect({ expandResolvers: true });
const transport = createHttpClientTransport({
baseUrl: "http://localhost:8000",
fetch
});
// Generic client
const client = createRestAPI2Client({ manifest, transport });
const health = await client.request({
operationId: "GET /api/v2/health"
});
// Fluent client
const root = createRootClient({ transport });
const spaces = await root.spaces.get();
const hub = root.space("space-id").hub("hub-id");
const sequences = await hub.sequences.get();
const inst = hub.instance("instance-id");
const instHealth = await inst.health.get();Stability
This package is labeled experimental in the curated reference. Its type contracts inform both client and server implementations. The package does not include MCP (Model Context Protocol) features.
See also
- API client usage for conceptual usage and examples.
- Legacy v1 API client for backwards-compatible
@scramjet/api-clientusage.
Install
npm install @scramjet/rest-api2Import
import { /* ... */ } from "@scramjet/rest-api2";Documentation
See the package docs for full documentation.
