💬 Chat Route Blocks
Chat route blocks provide pre-configured HTTP endpoints for chat management operations in Nodeblocks applications. These routes combine handlers, validators, and middleware to create complete API endpoints with proper authentication, authorization, and error handling.
🎯 Overview
Chat route blocks are designed to:
- Provide complete API endpoints for chat management operations
- Combine handlers with validators for secure operations
- Include authentication and authorization checks
- Support functional composition patterns
- Handle logging and error management automatically
📋 Route Structure
Each chat route follows a consistent pattern:
- HTTP Method: Defines the operation type (GET, POST, PATCH, DELETE)
- Path: Specifies the endpoint URL with parameters
- Handler: Composed function chain for business logic
- Validators: Authentication and authorization checks
🔧 Available Chat Routes
Channel Routes
createChatChannelRoute
Creates a new channel and returns the created resource.
Purpose: Handles channel creation with full resource retrieval
Route Details:
- Method:
POST
- Path:
/channels
- Authentication: Required (Bearer token)
Handlers: createChatChannel
, getChatChannelById
, createChatChannelTerminator
Validators: verifyAuthentication
(getBearerTokenInfo), validateChannelAccess
(['owner'], getBearerTokenInfo)
Usage:
import { routes } from '@nodeblocks/backend-sdk';
// Register route with Express app
app.use('/api', routes.createChatChannelRoute);
findChatChannelsRoute
Retrieves all channels with normalized list format.
Purpose: Lists channels with pagination
Route Details:
- Method:
GET
- Path:
/channels
- Authentication: Required (Bearer token)
Handlers: findChatChannels
, normalizeChatChannelsListTerminator
Validators: verifyAuthentication
(getBearerTokenInfo)
Usage:
import { routes } from '@nodeblocks/backend-sdk';
// Register route with Express app
app.use('/api', routes.findChatChannelsRoute);
getChatChannelRoute
Retrieves a specific channel by ID.
Purpose: Fetches channel data
Route Details:
- Method:
GET
- Path:
/channels/:channelId
- Authentication: Required (Bearer token)
Handlers: getChatChannelById
, normalizeChatChannelTerminator
Validators: verifyAuthentication
(getBearerTokenInfo)
Usage:
import { routes } from '@nodeblocks/backend-sdk';
// Register route with Express app
app.use('/api', routes.getChatChannelRoute);
updateChatChannelRoute
Updates an existing channel and returns the updated resource.
Purpose: Modifies channel data with access control
Route Details:
- Method:
PATCH
- Path:
/channels/:channelId
- Authentication: Required (Bearer token)
Handlers: updateChatChannel
, getChatChannelById
, normalizeChatChannelTerminator
Validators: verifyAuthentication
(getBearerTokenInfo), some(validateResourceAccess
(['admin'], getBearerTokenInfo), validateChannelAccess
(['owner'], getBearerTokenInfo))
Usage:
import { routes } from '@nodeblocks/backend-sdk';
// Register route with Express app
app.use('/api', routes.updateChatChannelRoute);
deleteChatChannelRoute
Deletes a channel by ID.
Purpose: Removes channel with access control
Route Details:
- Method:
DELETE
- Path:
/channels/:channelId
- Authentication: Required (Bearer token)
Handlers: deleteChatChannel
, deleteChatChannelTerminator
Validators: verifyAuthentication
(getBearerTokenInfo), some(validateResourceAccess
(['admin'], getBearerTokenInfo), validateChannelAccess
(['owner'], getBearerTokenInfo))
Usage:
import { routes } from '@nodeblocks/backend-sdk';
// Register route with Express app
app.use('/api', routes.deleteChatChannelRoute);
Subscription Routes
createChatSubscriptionRoute
Creates a new subscription and returns the created resource.
Purpose: Handles subscription creation with full resource retrieval
Route Details:
- Method:
POST
- Path:
/subscriptions
- Authentication: Required (Bearer token)
Handlers: createChatSubscription
, getChatSubscriptionById
, createChatSubscriptionTerminator
Validators: verifyAuthentication
(getBearerTokenInfo)
Usage:
import { routes } from '@nodeblocks/backend-sdk';
// Register route with Express app
app.use('/api', routes.createChatSubscriptionRoute);
findChatSubscriptionsRoute
Retrieves all subscriptions with normalized list format.
Purpose: Lists subscriptions with pagination
Route Details:
- Method:
GET
- Path:
/subscriptions
- Authentication: Required (Bearer token)
Handlers: findChatSubscriptions
, normalizeChatSubscriptionsListTerminator
Validators: verifyAuthentication
(getBearerTokenInfo)
Usage:
import { routes } from '@nodeblocks/backend-sdk';
// Register route with Express app
app.use('/api', routes.findChatSubscriptionsRoute);
getChatSubscriptionRoute
Retrieves a specific subscription by ID.
Purpose: Fetches subscription data
Route Details:
- Method:
GET
- Path:
/subscriptions/:subscriptionId
- Authentication: Required (Bearer token)
Handlers: getChatSubscriptionById
, normalizeChatSubscriptionTerminator
Validators: verifyAuthentication
(getBearerTokenInfo)
Usage:
import { routes } from '@nodeblocks/backend-sdk';
// Register route with Express app
app.use('/api', routes.getChatSubscriptionRoute);
deleteChatSubscriptionRoute
Deletes a subscription by ID.
Purpose: Removes subscription
Route Details:
- Method:
DELETE
- Path:
/subscriptions/:subscriptionId
- Authentication: Required (Bearer token)
Handlers: deleteChatSubscription
, deleteChatSubscriptionTerminator
Validators: verifyAuthentication
(getBearerTokenInfo)
Usage:
import { routes } from '@nodeblocks/backend-sdk';
// Register route with Express app
app.use('/api', routes.deleteChatSubscriptionRoute);
Message Routes
createChatMessageRoute
Creates a new message and returns the created resource.
Purpose: Handles message creation with full resource retrieval
Route Details:
- Method:
POST
- Path:
/messages
- Authentication: Required (Bearer token)
Handlers: createChatMessage
, getChatMessageById
, createChatMessageTerminator
Validators: verifyAuthentication
(getBearerTokenInfo), validateMessageAccess
(['owner'], getBearerTokenInfo)
Usage:
import { routes } from '@nodeblocks/backend-sdk';
// Register route with Express app
app.use('/api', routes.createChatMessageRoute);
findChatMessagesRoute
Retrieves all messages with normalized list format.
Purpose: Lists messages with pagination
Route Details:
- Method:
GET
- Path:
/messages
- Authentication: Required (Bearer token)
Handlers: findChatMessages
, normalizeChatMessagesListTerminator
Validators: verifyAuthentication
(getBearerTokenInfo)
Usage:
import { routes } from '@nodeblocks/backend-sdk';
// Register route with Express app
app.use('/api', routes.findChatMessagesRoute);
getChatMessageRoute
Retrieves a specific message by ID.
Purpose: Fetches message data
Route Details:
- Method:
GET
- Path:
/messages/:messageId
- Authentication: Required (Bearer token)
Handlers: getChatMessageById
, normalizeChatMessageTerminator
Validators: verifyAuthentication
(getBearerTokenInfo)
Usage:
import { routes } from '@nodeblocks/backend-sdk';
// Register route with Express app
app.use('/api', routes.getChatMessageRoute);
updateChatMessageRoute
Updates an existing message and returns the updated resource.
Purpose: Modifies message data with access control
Route Details:
- Method:
PATCH
- Path:
/messages/:messageId
- Authentication: Required (Bearer token)
Handlers: updateChatMessage
, getChatMessageById
, normalizeChatMessageTerminator
Validators: verifyAuthentication
(getBearerTokenInfo), some(validateResourceAccess
(['admin'], getBearerTokenInfo), validateMessageAccess
(['owner'], getBearerTokenInfo))
Usage:
import { routes } from '@nodeblocks/backend-sdk';
// Register route with Express app
app.use('/api', routes.updateChatMessageRoute);
deleteChatMessageRoute
Deletes a message by ID.
Purpose: Removes message with access control
Route Details:
- Method:
DELETE
- Path:
/messages/:messageId
- Authentication: Required (Bearer token)
Handlers: deleteChatMessage
, deleteChatMessageTerminator
Validators: verifyAuthentication
(getBearerTokenInfo), some(validateResourceAccess
(['admin'], getBearerTokenInfo), validateMessageAccess
(['owner'], getBearerTokenInfo))
Usage:
import { routes } from '@nodeblocks/backend-sdk';
// Register route with Express app
app.use('/api', routes.deleteChatMessageRoute);
🔗 Related Documentation
- Chat Domain Overview - Chat domain overview
- Chat Schemas - Chat validation schemas
- Chat Handlers - Chat business logic functions