Quick Start
Learn how to use Plasma in your project
1. Define your routes
Create a routes.ts file describing your API endpoints. Use z.object() for any query parameters that need validation or coercion.
import type { ServerRoutes } from '@crm/plasma'
import { z } from 'zod'
export const APP_ROUTES = {
'get-users': {
url: '/api/users',
params: z.object({
page: z.coerce.number().optional(),
role: z.enum(['admin', 'user']).optional(),
}),
returns: {} as { id: number; name: string }[],
},
'create-user': {
url: '/api/users',
apiPayload: z.object({
name: z.string(),
email: z.string().email(),
}),
returns: {} as { id: number; name: string; email: string },
},
} satisfies ServerRoutes2. Create the client
Instantiate createHttpClient once and export it for use across your app or create separate clients for different purposes.
import { } from '@crm/plasma'
import { } from './routes'
export const = ({
: ..,
: ,
: {
: [
async () => {
const = .('token')
if () ..('Authorization', `Bearer ${}`)
return
},
],
},
})3. Make requests
All methods return a Go-style [error, data] tuple — no try/catch needed.
const [, ] = await .('get-users', {
: { : 1, : 'admin' },
})
if () {
.()
throw
}
.()