Protocol translation in NestJS microservices

Making async microservices talk to clients that use "standard" web-friendly API protocols (think mobile and web applications) requires protocol translation. Here is a very simple idea, inspired by nats proxy project, on how to achieve it in NestJS with NATS microservice transport.

The complete source code for this article is available on Github. The README provides the setup and usage instructions as well as main files to look at. It's a Nx Monorepo that contains the following two applications:

  1. Gateway: This application exposes REST interface to clients, receives HTTP requests, dynamically forms the NATS subject name to send message to based on incoming request verb and path, sends the message to the subject, waits for NATS response from microservice and once received, sends out HTTP response back to client.
  2. Microservice: This application listens on NATS subject and responds with a string message when invoked.

The overall interaction looks like this: protocol-translator.png

That's it for today. Happy coding! À bientôt 🙋‍♂️!