Microservices Client API
Type-safe client library for communicating with NestJS microservices via message-based patterns.
What It Does
The Microservices Client API provides a lightweight, type-safe abstraction for communicating with NestJS-based microservices using message-based communication (Redis transport). It enables SDKs to expose domain objects to other services while maintaining clean separation of concerns—business logic stays in microservice controllers while clients remain thin routing layers.
Key Capabilities
| Capability | Description |
|---|---|
| Type-Safe Communication | Generic types ensure compile-time safety across service boundaries |
| CRUD Operations | Standardized get, getAll, query, create, add, update, delete methods |
| Hierarchical Resources | Native support for parent-child relationships (e.g., conversations/messages) |
| Observable-Based | RxJS Observables for reactive programming and composable async chains |
| Query Support | Complex filtering with ObjectQuery (gte, lte, AND operations) |
| Extensibility | Easily add custom methods beyond standard CRUD |
| Factory Pattern | Simple client creation with createClient() helper |
| Timestamp Metadata | Automatic timestamp inclusion in responses |
Configuration
Transport Configuration
- Default: Redis transport
- Configurable: Can use other NestJS transports
- Factory: createClient() helper for easy setup
Message Patterns
- Predefined in MicroservicePaths
- Convention-based routing
- Collection-scoped patterns
Exports
Factory Functions
MicroserviceClient<T, PathIdFn>()- Client factorycreateClient<Client>()- Pre-configured client creator
Interfaces
IMicroserviceClient<T, PathIdFn>- Client contract- Request models (IGetRequest, ICreateRequest, etc.)
- Response models (IGetResponse, ICreateResponse, etc.)
IMicroservicePayload<T>- Payload wrapper
Constants
MicroservicePaths- Message pattern definitions
Type Guards
isMicroservicePayload()- Payload validation
Common Use Cases
- Inter-service communication: Call other microservices from your service
- SDK development: Expose microservice operations to client applications
- Hierarchical data: Access nested resources (conversations/messages, products/reviews)
- Query operations: Search across microservice data
- Reactive patterns: Compose async operations with RxJS
- Thin client layer: Keep clients simple and updateable
What Customers Don’t Have to Build
- Message-based client infrastructure
- CRUD operation boilerplate
- Type-safe microservice communication
- Observable wrappers for async operations
- Message pattern routing
- Hierarchical resource support
- Query abstraction layers
- Response type definitions
- Timestamp metadata handling
- Client factory patterns
- Extension mechanisms for custom operations
- NestJS ClientProxy integration
Last updated on