Procedures
This documents the old v1 API. See Actors for the current version.
Procedures (incoming messages) are the client → server entry points in your Zocket router.
Anatomy of a Procedure
Section titled “Anatomy of a Procedure”- Input Validation (Optional)
- Middleware (Optional)
- Handler (Required)
const sendMessage = zo.message .use(authMiddleware) .input(z.object({ text: z.string() })) .handle(({ ctx, input }) => { console.log(ctx.clientId, input.text); });Input Validation
Section titled “Input Validation”.input( z.object({ title: z.string().min(1), tags: z.array(z.string()).max(5).optional() }))If the input is invalid, the handler will not run.
Async Handlers
Section titled “Async Handlers”Handlers can be asynchronous and return values (RPC style):
.handle(async ({ ctx, input }) => { const post = await db.post.create({ data: { title: input.title } }); return post;})