https://github.com/nimalank7/grpc_js
Simple gRPC client and server application that creates a todo list
https://github.com/nimalank7/grpc_js
grpc javascript learning
Last synced: about 2 months ago
JSON representation
Simple gRPC client and server application that creates a todo list
- Host: GitHub
- URL: https://github.com/nimalank7/grpc_js
- Owner: nimalank7
- Created: 2024-12-03T11:39:20.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-12-03T14:36:25.000Z (over 1 year ago)
- Last Synced: 2025-01-31T21:17:48.755Z (over 1 year ago)
- Topics: grpc, javascript, learning
- Language: JavaScript
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Application
Simple gRPC server that creates a todo list which a client application consumes. Tutorial from https://www.youtube.com/watch?v=Yw4rkaTc0f8
## Protocol Buffer
`todo.proto` is used in both `client.js` and `server.js` to generate a `Interface Definition Language`. This is to say it generates 'stubs' on the client (e.g. `client.readTodos(...)`) and lets the server know about these endpoints.
Here both the client and server use `@grpc/grpc-js` and `@grpc/proto-loader` to serialize/deserialize using Protocol Buffers into binary which are then sent across the wire. (Effectively performing the same function as the output of `protoc`)
## Run the application
In a separate terminal run:
```
npm run server
```
In a separate terminal run:
```
npm run client -- itemOne
npm run client -- itemTwo
npm run client -- itemThree
```
Note that running the client will call *all* the methods.
Sample output:
```
received item from server: {"id":1,"text":"itemOne"}
received item from server: {"id":2,"text":"itemTwo"}
received item from server: {"id":3,"text":"itemThree"}
Response from gRPC server upon `createTodo` method: {"id":3,"text":"itemThree"}
Response from gRPC server upon `readTodos` method: {"items":[{"id":1,"text":"itemOne"},{"id":2,"text":"itemTwo"},{"id":3,"text":"itemThree"}]}
server done!
```