Skip to Content
Engineering11 Documentation 🔥
BackendServer API PackagesMicroservices Client

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

CapabilityDescription
Type-Safe CommunicationGeneric types ensure compile-time safety across service boundaries
CRUD OperationsStandardized get, getAll, query, create, add, update, delete methods
Hierarchical ResourcesNative support for parent-child relationships (e.g., conversations/messages)
Observable-BasedRxJS Observables for reactive programming and composable async chains
Query SupportComplex filtering with ObjectQuery (gte, lte, AND operations)
ExtensibilityEasily add custom methods beyond standard CRUD
Factory PatternSimple client creation with createClient() helper
Timestamp MetadataAutomatic 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 factory
  • createClient<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