https://github.com/ihoro/rough-rx-grpc
The simplest RxJS wrapper around grpc lib
https://github.com/ihoro/rough-rx-grpc
grpc javascript nodejs protobuf reactive-extensions rxjs wrapper
Last synced: 7 months ago
JSON representation
The simplest RxJS wrapper around grpc lib
- Host: GitHub
- URL: https://github.com/ihoro/rough-rx-grpc
- Owner: ihoro
- License: mit
- Created: 2019-02-06T08:35:34.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-08-15T23:54:38.000Z (over 2 years ago)
- Last Synced: 2025-03-25T06:01:45.290Z (about 1 year ago)
- Topics: grpc, javascript, nodejs, protobuf, reactive-extensions, rxjs, wrapper
- Language: JavaScript
- Homepage:
- Size: 44.9 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# The simplest RxJS wrapper around grpc lib
[](https://travis-ci.com/ihoro/rough-rx-grpc)
[](https://badge.fury.io/js/%40rough%2Frx-grpc)
Rough implementation of [rxified](https://npmjs.com/rxjs) wrapper and tools for [grpc-js](https://www.npmjs.com/package/@grpc/grpc-js) lib.
## Usage example
```proto
// GreetingService.proto
syntax = "proto3";
package org.example;
service GreetingService {
rpc Greet(Request) returns (Response);
}
message Request {
string name = 1;
}
message Response {
string message = 1;
}
```
```js
// server.js
class GreetingService {
Greet(call, callback) {
const name = call.request.name;
if (name)
callback(null, { message: `Hello, ${name}!` });
else
callback(new Error('Name is not defined.'));
}
}
const RxGrpc = require('@rough/rx-grpc');
new RxGrpc()
.withProtoFiles(__dirname + '/*.proto')
.serve('org.example.GreetingService', new GreetingService())
.startServer()
.subscribe(
started => console.log('Listening at grpc://0.0.0.0:50051 ...'),
err => console.log(err),
complete => {}
);
```
```js
// client.js
const { flatMap } = require('rxjs/operators');
const RxGrpc = require('@rough/rx-grpc');
const rxgrpc = new RxGrpc().withProtoFiles(__dirname + '/*.proto');
const name = (process.argv.length > 2) ? process.argv[2] : null;
rxgrpc.service('org.example.GreetingService', 'localhost:50051').pipe(
flatMap(GreetingService => GreetingService.Greet({ name }))
)
.subscribe(
response => console.log(response.message),
err => console.log(err),
complete => {}
);
```