Skip to content

Introduction

This documents the old v1 API. See Getting Started for the current version.

Zocket is a type-safe WebSocket library that provides end-to-end type safety between client and server, inspired by tRPC. Build real-time applications with confidence using TypeScript and your favorite schema validation library (Zod, Valibot, or any Standard Schema compatible library).

  • End-to-end Type Safety: Full TypeScript inference from server to client. Change your server code, and your client code updates automatically.
  • Schema Validation: Works with Zod, Valibot, and any Standard Schema compatible library to validate inputs and outputs.
  • Real-time Rooms: Built-in support for WebSocket rooms/channels for targeted broadcasting (e.g., chat rooms, notifications).
  • Middleware Support: Composable middleware for authentication, logging, error handling, and context injection.
  • Runtime Agnostic: Server is adapter-based (Bun adapter included today) and the client works anywhere with WebSocket.
  • Framework Agnostic: Use with any framework (Next.js, Nuxt, React, Vue) or vanilla JS/TS.

Building real-time applications often involves manually syncing types between the backend and frontend. If you change a message structure on the server, you have to remember to update the client code.

Zocket solves this by inferring types directly from your server router.

Socket.io is great but lacks built-in end-to-end type safety. You often have to maintain shared interface definitions manually. Zocket gives you the same real-time capabilities (rooms, broadcasting) but with the developer experience of tRPC.

tRPC is amazing for request/response (HTTP/RPC) flows. Zocket brings that same DX to WebSockets and Event-driven architectures, where the server can push data to the client at any time, not just in response to a request.