Plasma
Core concepts

Route Definitions

Learn how to define routes in Plasma

Routes are plain objects that satisfy the ServerRoutes type and can be consumed by createHttpClient.

FieldTypeDescription
url`/${string}`Endpoint path (must start with /)
paramsz.ZodObjectQuery parameters schema — enables validation and coercion
apiPayloadz.ZodObjectRequest body schema — validated before the request is sent
clientInputz.ZodObjectInput schema for the UI layer (e.g. form validation) — not sent to the API
returnsunknownShape of the API response (type-only, not runtime)

Example

routes.ts
import type { ServerRoutes } from '@crm/plasma'
import {  } from 'zod'

const  = {
    "get-users": {
        : `/api/users`,
        : .({
            : ..().(),
            : ..().(),
        }),
        : {} as { : number; : string }[]
    },
    "get-profile": {
        : `/api/users/profile`,
        : {} as { : number; : string }
    },
    "create-user": {
        : `/api/users`,
        : .({
            : .(),
            : .(),
        }),
        : {} as { : number; : string }
    }
} satisfies ServerRoutes
service.ts
import {  } from "./client";

const [, ] = await .("
  • get-users
  • get-profile
  • create-user
");

On this page