/gRPC

NodeJS repository for hands-on exploration of gRPC, a high-performance remote procedure call framework

Primary LanguageTypeScript

Node gRPC Microservices Communication

This project has been created to learn how to set up gRPC communication between microservices.

How to Run the Project

  1. Clone the repository:
git clone https://github.com/alejandromc23/gRPC.git
  1. Install dependencies:
pnpm install
  1. Build files:
pnpm build
  1. Start the dummy server
cd services/@state-transitions/service
pnpm start

Sending Requests

To make requests simulating a client, you can use curl from your console. Here are the example requests:

  1. Health Check:
curl
--header 'Content-Type: application/json'
--data {}
http://localhost:8080/proto.transitions.v1.StateTransitionService/HealthCheck

Response will be:

Response:
```json
{"status":"SERVING_STATUS_SERVING"}
  1. Send State Transition:
curl \
  --header 'Content-Type: application/json' \
  --data '{
    "user": "9fke93ur23-1",
    "block": "394208feop12e",
    "version": 0,
    "transition": "next",
    "timestamp": "1099-10-21T07:52:58Z"
  }' \
  http://localhost:8080/proto.transitions.v1.StateTransitionService/StateTransition

Response:

{}
  1. Get State Transition:
curl \
  --header 'Content-Type: application/json' \
  --data '{
    "user": "9fke93ur23-1",
    "block": "394208feop12e",
    "version": 1
  }' \
  http://localhost:8080/proto.transitions.v1.StateTransitionService/GetStateTransition
{"user":"9fke93ur23-1","block":"394208feop12e","version":1}

Project Structure

The project structure includes the following directories:

  • services/@state-transitions/definition: Contains the proto files that define the communication. Running pnpm build will convert the proto definitions into TypeScript inside the src folder.

  • services/@state-transitions/service: Represents a dummy Fastify server where you can test the requests.

Credits

This repository has been built following the tutorial Building a Modern gRPC-Powered Microservice from dopt.