open-index/open-npm huggingface dataset:
npm package: @hmviet/webrpc-ts
Description: ```sh npm i @hmviet/webrpc-ts ```
Author: hmviet
Latest version: 1.0.16

## Install package

```sh
npm i @hmviet/webrpc-ts
```

## A. Docs

## grpcClient.unary

```ts
unary(
  url: string,
  data: RpcMetaData,
  options?: UnaryOptions
): Promise<RpcResponse>;
```

## grpcClient.clientStream

```ts
clientStream(url: string, options?: StreamOptions): Stream;
```

## grpcClient.serverStream

```ts
serverStream(
    url: string,
    data: RpcMetaData,
    options?: StreamOptions
  ): Stream;
```

## grpcClient.stream

```ts
stream(url: string, options?: StreamOptions): Stream;
```

## B. Sample code

## Init Client

```tsx
const clientOptions: ClientRpcOptions = {
  host: "https://localhost.com",
  // custom websocket end point.
  streamEndPoint: "/examples.time.Time/ws",
};
const grpcClient = new Client(clientOptions);
```

## 1. Fetch Unary

```tsx
//options
const options: UnaryOptions = {
  // false: fetch via GET
  // true : fetch via POST
  query: false,
  // custom headers
  headers: {
    // your headers
  },
};
// req
const data: RpcMetaData = newData();
// make request
const res = await grpcClient.unary("/examples.time.Time/Unary", data, options);
```

## 2. Client Stream

```tsx
const options: StreamOptions = {
  // custom headers
  headers: {
    // your headers
  },
};
const url = "/examples.time.Time/ClientStream";
const stream = grpcClient.clientStream(url, options);
// send
const data: RpcMetaData = newData();
// do send message
tream.send(data);
const data2: RpcMetaData = newData();
stream.send(data2);
// close send
stream.closeSend();
// wait response
const res = await stream.receive();
```

## 3. Server Stream

```tsx
const url = "/examples.time.Time/ServerStream";
const data: RpcMetaData = newData();
const options: StreamOptions = {
  // custom headers
  headers: {
    // your headers
  },
};
const stream = grpcClient.serverStream(url, data, options);
// wait receive data
const res = await stream.receive();
```

## 4. Bidi Stream

```tsx
const options: StreamOptions = {
  headers: {},
  onResponse: (message: RpcMessage) => {
    // streaming response
    console.log("onResponse", message);
  },
};
const url = "/examples.time.Time/Stream";
const stream = grpcClient.stream(url, options);
// send
const data: RpcMetaData = newData();
// do send message
tream.send(data);
const data2: RpcMetaData = newData();
stream.send(data2);
// close send
stream.closeSend();
```

![Screenshot 2022-12-29 at 07 57 51](https://user-images.githubusercontent.com/11186990/209891384-324d3415-2999-4b09-ada8-ed36b82fbd92.png)