How to use gRPC reflection in a browser client without Node.js?

I would like my React.js web application to be able to connect to my gRPC server implementing the gRPC Server Reflection Protocol.

Using gRPC reflection would allow the web app to discover and use methods dynamically instead of having to import proto files.

I took a look at some libraries like grpc-js-reflection-api-client and gprc-reflection-js, but these assume a Node.js runtime through their dependency on @grpc/grpc-js, and it doesn’t seem feasible to run them from a browser application.

Is there another way to use gRPC reflection, using libraries like grpc-web perhaps?

Here is a simple example along the lines of what I would like to do (code snippet from grpc-js-reflection-api-client):

const { GrpcReflection } = require('grpc-js-reflection-client');
const grpc =  require('@grpc/grpc-js');

function getChannelCredentials() {
    return grpc.ChannelCredentials.createSsl();
}

(async()=> {
    const client = new GrpcReflection(
        'grpcb.in:9001',
        getChannelCredentials(),
    );
    console.log(await client.listServices());
})();

Leave a Comment