This project has been created to learn how to set up gRPC communication between microservices.
- Clone the repository:
git clone https://github.com/alejandromc23/gRPC.git
- Install dependencies:
pnpm install
- Build files:
pnpm build
- Start the dummy server
cd services/@state-transitions/service
pnpm start
To make requests simulating a client, you can use curl
from your console. Here are the example requests:
- 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"}
- 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:
{}
- 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}
The project structure includes the following directories:
-
services/@state-transitions/definition
: Contains the proto files that define the communication. Runningpnpm build
will convert the proto definitions into TypeScript inside thesrc
folder. -
services/@state-transitions/service
: Represents a dummy Fastify server where you can test the requests.
This repository has been built following the tutorial Building a Modern gRPC-Powered Microservice from dopt.