What is the BloxChat API?
BloxChat uses tRPC to provide a type-safe, end-to-end API for real-time chat communication. Built on top of tRPC’s modern RPC framework, the API offers both HTTP and WebSocket support for queries, mutations, and real-time subscriptions.tRPC eliminates the need for traditional REST endpoints by providing direct, type-safe function calls between client and server.
API Structure
The BloxChat API is organized into two main routers:Auth Router
Handles user authentication, verification flows, and JWT token management
Chat Router
Manages chat messages, subscriptions, and rate limiting
Router Definition
The API structure is defined inpackages/api/src/root.ts:
packages/api/src/root.ts
Connection Methods
BloxChat supports dual-protocol communication for maximum flexibility:HTTP Adapter
Used for queries and mutations:WebSocket Adapter
Required for real-time subscriptions:Base URL
The default server configuration runs on:In production, replace
localhost:3000 with your deployed API endpoint.WebSocket Subscriptions
BloxChat leverages tRPC’s subscription capabilities for real-time features:- Chat messages: Real-time message delivery via
chat.subscribe - Automatic reconnection: Server broadcasts reconnect notifications on shutdown
- Channel-based: Subscribe to specific channels for filtered message streams
Example Subscription
Rate Limiting
BloxChat implements comprehensive rate limiting at multiple levels:Authentication Endpoints
Authentication Endpoints
- Refresh tokens: 4 requests per hour per user
- Game verification: 20 requests per minute per user
- Check verification: 60 requests per minute per session
Chat Endpoints
Chat Endpoints
Rate limits are configurable per channel via
getChatLimitsForChannel():- Message length limits
- Message rate limits (requests per time window)
- Configurable per channel for flexibility
Procedure Types
BloxChat defines three types of procedures:| Procedure Type | Authentication | Use Case | Example |
|---|---|---|---|
publicProcedure | None | Public endpoints | auth.beginVerification |
protectedProcedure | JWT required | Authenticated actions | chat.publish |
gameVerificationProcedure | Verification secret | Game server callbacks | auth.completeVerification |
Error Handling
tRPC uses standardized error codes. Common BloxChat errors:Next Steps
Authentication
Learn how JWT authentication works in BloxChat
Begin Verification
Start the authentication flow
Publish Messages
Send messages to chat channels
tRPC Documentation
Deep dive into tRPC concepts