Docs
Functions

createKizlo

Create a Kizlo server, procedure tree, client, request handler, and WordPress client 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 configured wordpress client. 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.
wordpressThe configured WordPress client, with generated endpoints and raw transport methods for server code.

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, wordpress, 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, wordpress, 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, wordpress, 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.

Call WordPress directly

src/app/posts.ts
import { wordpress } from "@/lib/kizlo/server"

const result = await wordpress.kizlo.postTypes.post.list({ query: { per_page: 10 } })

Direct calls use your configured WordPress credentials and bypass Kizlo procedure middleware. Keep wordpress in server code; never export it from your browser client entry. Procedures and middleware still receive their invocation context, including context.wordpress.

Migrate existing access

Replace public createWordPressClient imports and kizlo.context.createServerContext().wordpress with kizlo.wordpress, or destructure wordpress from createKizlo({ integrations, introspection }). The factory is now internal and Kizlo.context is private. Export wordpress instead of context from your server entry; use a procedure's context for its session, cookies, and other services.

On this page