Giter Site home page Giter Site logo

fossabot / grpc-man Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jeff-tian/grpc-man

0.0 1.0 0.0 313 KB

A client to call gRPC server methods on the fly. 一个 gRPC 客户端,可以灵活地调用 gRPC 服务。

Home Page: https://www.npmjs.com/package/grpc-man

License: Other

TypeScript 91.03% JavaScript 8.97%

grpc-man's Introduction

grpc-man

A client to call gRPC server methods on the fly. 一个 gRPC 客户端,可以灵活地调用 gRPC 服务。

名字灵感来源于 post-man

996.icu LICENSE Build Status NPM version npm download Dependencies Status semantic-release Git commit with emojis! FOSSA Status

Quality gate

有什么用?

本包提供了一个轻量级的 gRPC 客户端实现,可以用来快速验证你的 gRPC 服务是否正确工作。

当然,它只提供了连接 gRPC 服务的方法,具体运行结果需要自行写代码验证。

作者在实际项目中使用 Mocha 测试框架,也非常推荐你使用它。后面会有在 Mocha 框架中使用此包的示例代码。

当然,你也可以在别的测试框架中使用本包,比如本项目自身使用了 jestjest 很优秀,但实际使用下来,我感觉不如 Mocha 快)。

安装:

# 如果你想全局运行:
npm install -g grpc-man

# 如果你想在项目的测试代码里使用它:
npm install --save-dev grpc-man

用在 javascript 项目里:

import GrpcClient from 'grpc-man/lib/Client';

async function main() {
  const client = new GrpcClient('<yourhost>:<your port>', __dirname + 'your.proto');

  await client.grpc.youpackage.YourService.yourMethod(arg);
}

用在测试里:

如果你的项目使用 gRPC 为客户提供服务,那么在你的项目的自动化测试中,你可以用它来帮助调用你的 gRPC 服务:

mocha 示例

示例用到的 proto 文件在这里

import assert = require('assert');
import GrpcClient from 'grpc-man/lib/Client';

describe('grpc', () => {
  it('可以打招呼', async () => {
    const client = new Client('0.0.0.0:8899', __dirname + '/./proto/helloworld.proto');

    const res = await client.grpc.helloworld.Greeter.sayHello({ name: 'name' });
    assert.deepEqual(res, { message: 'Hello name' });
  });
});

如果你采用 jest 测试框架,那么可以参考本包的测试代码

命令行使用

grpc-man <endpoint> <protoFilePath>

# for example:
grpc-man localhost:8080 /path/to/proto_file

本地运行

npm start <endpoint> <protoFilePath>

# for example:
npm start localhost:8080 /path/to/proto_file

License

FOSSA Status

grpc-man's People

Contributors

fossabot avatar jeff-tian avatar

Watchers

 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.