Skip to content

waygraph / defineApiBlock

Function: defineApiBlock() ​

defineApiBlock<In, Out>(options): DefinedBlock<In, Out>

Defined in: src/engine/block/kinds/api.ts:94

A Block whose act() is a real HTTP request, not a page interaction - lets one Flow narrate a UI step (.gotoPage()) and a backend check (.method(checkOrderCreated)) as the same state machine, checked by the same Trait/verify system. Runs through page.request, so it shares the browser context's cookies/origin - no separate auth dance for an already-logged-in session.

Type Parameters ​

In ​

In extends Checkpoint<string>

Out ​

Out extends Checkpoint<string>

Parameters ​

options ​

ApiBlockOptions<In, Out>

Returns ​

DefinedBlock<In, Out>

Example ​

ts
const CheckOrderCreated = defineApiBlock({
  name: "check-order-created",
  from: InventoryPage,
  to: [OrderConfirmed, OrderFailed],
  call: ({ request }) => request.get("/api/orders/latest"),
  resolve: (r) => (r.ok ? OrderConfirmed : OrderFailed),
  verify: [Trait.disabled],
});

waygraph 0.18.3 (alpha) · Node 24+ · peer @playwright/test ^1.40.0 · syntax may change before 1.0: see what was removed