Docs
Functions

createKizlo

Create a Kizlo server, procedure tree, client, request handler, and context for your app.

createKizlo builds your Kizlo server from credentials and registered integrations. It returns the handler you mount on a route, a server-to-server client, the resolved procedures, and the context. Call it once and export the pieces you need.

Parameters

createKizlo(options?)

Every field is optional. Runtime integrations contribute the connection values their environment provides. Kizlo does not read environment variables itself. It resolves the active local or remote WordPress values from the canonical mode, remote, and local values after integrations map and compose them.

Prop

Type

When neither an explicit option nor an integration supplies a required value, Kizlo throws MISSING_ENV_VALUE with the missing camel-case key.

integrations takes the integrations whose procedures, events, adapters, environment values, and requirements Kizlo composes. logging enables the built-in console logger at error, warn, info, or debug; see Adapter precedence.

Returns

A Kizlo instance with four members:

MemberDescription
handler(request: Request) => Promise<Response>, the fetch handler to mount on your server route. It is pre-bound, so destructuring keeps it working.
clientA server-to-server client for calling your own procedures from server code.
proceduresThe resolved procedure tree: core procedures, namespaced integration procedures, and webhooks.
contextThe shared server context passed to procedures and middleware.

Examples

On a Node server, map process.env through the Node integration:

src/lib/kizlo/server/index.ts
import { createKizlo } from "kizlo"
import { node } from "kizlo/node"

export const { procedures, client, handler } = createKizlo({
  integrations: [node()],
})

With a framework and provider integration registered:

src/lib/kizlo/server/index.ts
import { createKizlo } from "kizlo"
import { nextjs } from "kizlo/nextjs/server"
import { reviews } from "./reviews"

export const { procedures, client, handler } = createKizlo({
  integrations: [nextjs(), reviews()],
})

With the generated introspection and console logging:

src/lib/kizlo/server/index.ts
import { createKizlo } from "kizlo"
import { nextjs } from "kizlo/nextjs/server"
import { introspection } from "./generated"

export const { procedures, client, handler } = createKizlo({
  integrations: [nextjs()],
  introspection,
  logging: "debug",
})

introspection is the tree that types the WordPress client. Pass the introspection export of your generated barrel; WordPress credentials resolve from the values your integrations contribute.

On this page