Skip to content

kattsushi/loopback4-extension-socketio

Repository files navigation

gRPC Extension for LoopBack 4

Join the chat at https://gitter.im/strongloop/loopback4-extension-grpc

Overview

The @loopback/grpc component enables LoopBack 4 as a gRPC Server. Also it provides with a gRPC decorator to define your RPC Method implementations from your Application Controllers.

Installation

Install the @loopback/grpc component in your LoopBack 4 Application.

$ npm install --save @loopback/grpc

Component Configuration

import {Application} from '@loopback/core';
import {GrpcComponent, GrpcConfig} from '@loopback/grpc';
import {MyGreeter} from './MyGreeter';

const config: GrpcConfig = {
    proto: './file.proto',
    package: 'myawesomepackage'
}

const app = new Application({
    components: [GrpcComponent],
    grpc: config
});

app.controller(MyGreeter});

await app.start();

Grpc Decorator

The @loopback/grpc component provides you with a handy decorator to implement GRPC Methods.

import {grpc} from '@loopback/grpc';
// You create the following types according your own proto.file
import {Greeter, HelloRequest, HelloReply} from './types';
/**
 * @class MyGreeter
 * @description Implements grpc proto service
 **/
export class MyGreeter implements Greeter {
    // Tell LoopBack that this is a Service RPC implementation
    @grpc()
    SayHello(request: HelloRequest): HelloReply {
        const reply: HelloReply = {message: 'Hello ' + request.name};
        return reply;
    }
}

Contribute

Get started by either downloading this project or cloning it as follows:

$ git clone https://github.com/strongloop/loopback4-extension-grpc.git
$ cd loopback4-extension-grpc && npm install

Contributions

Tests

run npm test from the root folder.

Contributors

See all contributors.

License

MIT

About

Extension socktio / websockets for loopback-next

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published