# apipost-grpc

> apipost-grpc

Latest version **2.0.7** (published 2024-05-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install apipost-grpc
pnpm add apipost-grpc
yarn add apipost-grpc
bun add apipost-grpc
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.7 |
| Published | 2024-05-17 |
| First published | 2022-07-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 14 |
| Unpacked size | 44.3 KB |
| Known vulnerabilities | 0 (+12 in 3 direct dependencies) |
| Install scripts | no |
| Author | apipost-lab001 |
| Maintainers | chengyang12138, proud_lion, lee-meng, wjzhangq, apipost-lab001, xbw19975 |
| Keywords | grpc, apipost-grpc, apipost |

## Links

- npm: https://www.npmjs.com/package/apipost-grpc
- Repository: https://github.com/Apipost-Team/apipost-grpc
- Homepage: https://github.com/Apipost-Team/apipost-grpc#readme
- Issues: https://github.com/Apipost-Team/apipost-grpc/issues
- npm.io page: https://npm.io/package/apipost-grpc

## Dependencies (14)

- [uuid](https://npm.io/package/uuid.md) ^8.3.2
- [json5](https://npm.io/package/json5.md) ^2.2.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [mockjs](https://npm.io/package/mockjs.md) ^1.1.0
- [core-js](https://npm.io/package/core-js.md) ^3.9.0
- [crypto-js](https://npm.io/package/crypto-js.md) ^4.2.0
- [protobufjs](https://npm.io/package/protobufjs.md) ^6.11.3
- [grpc-caller](https://npm.io/package/grpc-caller.md) ^0.14.0
- [@grpc/grpc-js](https://npm.io/package/@grpc/grpc-js.md) ^1.6.7
- [apipost-tools](https://npm.io/package/apipost-tools.md) ^0.0.34
- [@grpc/proto-loader](https://npm.io/package/@grpc/proto-loader.md) ^0.6.13
- [grpc-reflection-js](https://npm.io/package/grpc-reflection-js.md) ^0.3.0
- [apipost-inside-tools](https://npm.io/package/apipost-inside-tools.md) ^0.1.10
- [protocol-buffers-schema](https://npm.io/package/protocol-buffers-schema.md) ^3.6.0

## Recent versions

- 2.0.7 (latest) — 2024-05-17
- 2.0.6 — 2024-05-16
- 2.0.5 — 2024-04-29
- 2.0.4 — 2024-04-28
- 2.0.3 — 2024-04-25
- 2.0.2 — 2024-04-18
- 2.0.1 — 2023-12-13
- 2.0.0 — 2023-12-12
- 0.0.23 — 2023-12-11
- 0.0.22 — 2023-12-11
- 0.0.21 — 2023-12-11
- 0.0.20 — 2023-12-11
- 0.0.18 — 2023-08-29
- 0.0.17 — 2023-08-15
- 0.0.16 — 2022-11-11
- … 12 more at https://npm.io/package/apipost-grpc/versions

## README

<p align="center">
  <a href="https://adesign.apipost.cn/" target="_blank">
    <img alt="A-Design Logo" width="360" src="https://img.cdn.apipost.cn/cdn/opensource/apipost-opensource.svg" />
  </a>
</p>

# 🚀 apipost-grpc
Apipost 的 gRpc 模块，支持模拟 gRpc client 进行请求，并支持请求参数的Mock。

Apipost8 支持

## Install

```
$ npm install apipost-grpc 
```

## 使用

```
const gRpcClient = new ApipostGrpc({
    proto:path.resolve(__dirname, './protos/HelloWorld.proto'),
    // ssl:{
    //     ca:path.resolve(__dirname, './cert/CA.crt'),
    //     key:path.resolve(__dirname, './cert/CLIENT_key.pem'),
    //     cert:path.resolve(__dirname, './cert/CLIENT.crt')
    // }
});
```

# request(service, method, target) 

**示例**：发送 gRpc 请求

```
let target = {
    "request": {
        "url": "127.0.0.1:50051",
        "header": [
            {
                "is_checked": "1",
                "key": "content-type",
                "value": "1111111"
            }
        ],
        "body": {
            "raw": `{"name": "jim", "city":"上海"}`
        }
    }
};
gRpcClient.request('Greeter', 'SayHello', target).then(function (response) {
    console.log(response)
})
```

# serverList() 

**示例**：获取所有 server 列表

```
gRpcClient.serverList()

```
返回：

```
[
    {
        "short": "Greeter", // 服务短名称
        "service": "helloworld.Greeter" // 服务长名称（带 namespac）
    }
]
```

# allMethodList() 

**示例**：获取所有 method 列表

```
gRpcClient.allMethodList()

```
返回：

```
{
    "helloworld.Greeter": { // 服务名（带 namespace）
        "service": "Greeter", // 服务名
        "method": [
            {
                "name": "SayHello", // 方法名
                "requestBody": { // 示例请求参数
                    "name": "本起层感去交",
                    "city": "性压件地经阶"
                }
            },
            {
                "name": "printAge",
                "requestBody": {
                    "age": "产年取产"
                }
            }
        ]
    }
}
```

# methodList(server) 

**示例**：获取指定server的method 列表

```
gRpcClient.methodList('helloworld.Greeter')

```
返回：

```
{
    "service": "Greeter", // 服务名
    "method": [
        {
            "name": "SayHello", // 方法名
            "requestBody": { // 示例请求参数
                "name": "果现不参应非",
                "city": "而而保"
            }
        },
        {
            "name": "printAge",
            "requestBody": {
                "age": "资着己南段"
            }
        }
    ]
}
```

---
_Source: https://npm.io/package/apipost-grpc · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
