Skip to main content

Quickstart

This guide walks through the three entry points in order: the UI-first client, the scripted debugger, and long-lived manual sessions.

Prerequisites

  • Node.js 18 or later
  • An OpenAPI 3.2 document loaded as a JavaScript object

1. UI-first client

createClient(options?) returns a ProtoClient. The options argument is optional and controls write-back and response normalization.

import { createClient } from "@powerduck/openapi-request";

// Create a client (options are optional)
const client = createClient({
writeBack: {
// Optional: control how responses are merged back into the spec
mergeExamples: true,
},
response: {
// Optional: control how response objects are normalized
preserveOriginalBody: false,
},
});

Plan a request

prepare(sendOptions) takes a SendOptions object with spec and target, and returns a PreparedRequest describing protocol, display mode, and stream kind.

const spec = {
openapi: "3.2.0",
info: { title: "Example API", version: "1.0.0" },
paths: {
"/users/{id}": {
get: {
operationId: "getUserById",
parameters: [
{ name: "id", in: "path", required: true, schema: { type: "string" } },
],
responses: { "200": { description: "OK" } },
},
},
},
};

// Target by operationId (recommended)
const plan = client.prepare({
spec,
target: { operationId: "getUserById" },
});

// Or target by method + path
const plan2 = client.prepare({
spec,
target: { method: "GET", path: "/users/{id}" },
});

console.log(plan.protocol); // "http"
console.log(plan.display.mode); // "response"
console.log(plan.stream.kind); // "none"

Send a request

send(sendOptions) also takes a SendOptions object. Pass concrete values through values.

const result = await client.send({
spec,
target: { operationId: "getUserById" },
values: {
path: { id: "42" },
query: { include: "profile" },
header: { "X-Request-Id": "abc-123" },
},
serverUrl: "https://api.example.com",
auth: {
type: "bearer",
token: "your-token-here",
},
timeout: 15000,
});

console.log(result.response.status); // e.g. 200
console.log(result.response.body); // parsed response body
console.log(result.response.headers); // response headers
console.log(result.response.timings.durationMs); // duration in ms

Send a batch

sendMany(spec, targets, shared?) runs multiple requests and returns per-target results. Failures never discard successful siblings.

const batchResult = await client.sendMany(
spec,
[
{ target: { operationId: "getUserById" }, values: { path: { id: "1" } } },
{ target: { operationId: "getUserById" }, values: { path: { id: "2" } } },
{ target: { operationId: "getUserById" }, values: { path: { id: "3" } } },
],
{
serverUrl: "https://api.example.com",
auth: { type: "bearer", token: "your-token" },
},
);

batchResult.results.forEach((r, i) => {
if ("error" in r) {
console.log(`Request ${i} failed:`, r.error);
} else {
console.log(`Request ${i} status:`, r.response.status);
}
});

2. Scripted debugger

createDebugger(config?) returns a ProtoKit for automation, scripts, and CI.

import { createDebugger } from "@powerduck/openapi-request";

const debugger = createDebugger({
// Optional: custom adapter list
// adapters: [new HttpAdapter(), new WebSocketAdapter()],
// Optional: extra adapters added to the defaults
// extraAdapters: [new MyCustomAdapter()],
writeBackTruncated: true,
});

// Single request
const result = await debugger.send({
spec,
target: { operationId: "getUserById" },
values: { path: { id: "42" } },
serverUrl: "https://api.example.com",
});

// Batch request
const batch = await debugger.sendMany(
spec,
[
{ target: { operationId: "listUsers" } },
{ target: { operationId: "getUserById" }, values: { path: { id: "1" } } },
],
{ serverUrl: "https://api.example.com" },
);

// Export as Postman-compatible collection
const collection = debugger.toCollection(spec, {
name: "My API Collection",
});

3. Long-lived manual sessions

createManualSession(options) returns a duplex session for WebSocket, MCP, and gRPC.

import { createManualSession } from "@powerduck/openapi-request";

const session = createManualSession({
protocol: "websocket",
url: "wss://api.example.com/ws",
// For MCP:
// protocol: "mcp",
// transport: "http", // or "stdio"
// url: "https://api.example.com/mcp",
// For gRPC:
// protocol: "grpc",
// url: "localhost:50051",
});

// Open the connection
await session.open();

// Send a message
await session.send({ type: "message", data: "hello" });

// Subscribe to events
const unsubscribe = session.subscribe((event) => {
console.log("Event:", event.type, event.data);
});

// Close when done
await session.close();
unsubscribe();

Next steps