Giter Club home page Giter Club logo

grpcc's Introduction

grpcc Circle CI

grpcc is a flexible command-line client for any gRPC server for quick and easy testing of APIs. grpcc is writtern in nodejs but can talk to a gRPC service written in any language.

This is an example of using grpcc with the Skizze database's gPRC .proto file:

Features

  • Easy to create flexible connections to gRPC services for testing
  • Supports auto-reconnect via the standard gRPC backoff-retries
  • In-built, simple to use, printReply function for handling service replies
  • Use Javascript objects to mimic protobuf Message objects

Installation

npm install -g grpcc

Getting Started

grpcc is meant to be used as a quick way to connect to gRPC services to easily execute remote methods. I use it primarily during development, as it allows me to not have to worry about writing client bindings while I'm experiementing with service API.

To use it, you only need the service's .proto file, which describes the RPC service, and the address (host:port) of the service. grpcc can talk to local or remote services:

$ grpcc --proto ./service/myservice.proto --address 127.0.0.1:3466

By default, grpcc will attempt to make a secure connection to the service. If you need an insecure connection, you can pass in the -i flag.

Once grpcc has connected, it will print out usage instructions for the configured service. It does this by reading the parsed values from the protobuf file. After printing the instructions, it will start a nodejs REPL with the following globals available:

  • client - this is the gRPC client connection to your service. The usage instructions will show the available mehtods, as will using tab completion by typing client.<tab>
  • printReply - this is a convenience callback for printing the response of an RPC call (nicer than console.log)
  • pr - this is an alias for printReply

The REPL environment is using --harmony and detects methods that should have use strict, so feel free to use the es6 features that nodejs supports.

Arguments, Callbacks, & Streaming

Depending on whether your method is a simple call or a streaming call, you'll have to do different things:

  • All calls require an argument matching the spec, so if you have an empty message type in your proto for some calls, you'll be sending in {} as the first argument to those calls
  • Remember that Protobuf.js will camelCase class and property names
  • Simple calls can take a callback as the second argument which has the signature function(err, reply). reply will be an object matching the message type as per your proto
  • For streaming calls, you'll want to use the EventEmitter object that is returned when the call is made and connect to the appropriate events

The official nodejs gRPC docs cover how to use these features very well.

Usage

  Usage: grpcc [options]

  Options:

    -h, --help                 output usage information
    -V, --version              output the version number
    -p, --proto <path>         path to a protobuf file describing the service (required)
    -d, --directory <path>     path to a protobuf file directory (optional, default as command running directory)
    -a, --address <host:port>  the address of the service to connect to (required)
    -s, --service <name>       the name of the service to connect to (optional)
    -i, --insecure             use an insecure connection (default=false)

Versions

0.0.8

  • Force min grpc version of 1.4.1 #21

0.0.7

  • Let's not talk about this.

0.0.6

  • Fix version mismatch (thanks @ehudc)
  • Fix UnhandledPromiseRejectionWarning (thanks @jfyne)
  • Fix handling dot-delimited packabes (thanks @rodrigosetti)

0.0.5

  • Update to grpc v1.0

0.0.4

  • ๐Ÿ™ƒ

0.0.3

  • Support multiple packages & loading of multiple protobufs (thank you @chakming)

0.0.2

  • Fix bug where proto files without a service declaration wouldn't load #4

0.0.1

  • Initial Release

Todo

  • Intercept more known error messages from gRPC bindings and pretty-print them
  • REPL history between sessions
  • Nicer API for streaming (all types), e.g. a function wrapper that listens to the events and pretty prints
  • Easily reload the client (when proto changes)

License

MIT

Contact

Neil Jagdish Patel

Github Twitter Blog

grpcc's People

Contributors

njpatel avatar chakming avatar kenny-house avatar macalinao avatar jfyne avatar jwall149 avatar ehudc avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.