# drpc_dweb

> Simple RPC with Protobuf services.

Latest version **1.0.2** (published 2021-03-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install drpc_dweb
pnpm add drpc_dweb
yarn add drpc_dweb
bun add drpc_dweb
```

Provides the command `drpc`.

## 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 | 1.0.2 |
| Published | 2021-03-05 |
| First published | 2021-03-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 18.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | PeepsLabs |
| Maintainers | dwebprotocol |

## Links

- npm: https://www.npmjs.com/package/drpc_dweb
- Repository: https://github.com/dwebprotocol/drpc
- Homepage: https://dwebx.org
- Issues: https://github.com/dwebprotocol/drpc/issues
- npm.io page: https://npm.io/package/drpc_dweb

## Dependencies (3)

- [minimist](https://npm.io/package/minimist.md) ^1.2.5
- [protocol-buffers](https://npm.io/package/protocol-buffers.md) ^4.1.2
- [protocol-buffers-schema](https://npm.io/package/protocol-buffers-schema.md) ^3.4.0

## Recent versions

- 1.0.2 (latest) — 2021-03-05
- 1.0.1 — 2021-03-05
- 1.0.0 — 2021-03-05

## README

# drpc_dweb

Simple RPC with Protobuf Services

```
npm install drpc_dweb
```

## Usage

First define an RPC service

```proto
message Echo {
  required string value = 1;
}

service Example {
  rpc Echo (Echo) returns (Echo) {}
}
```

Then compile it using the drpc_dweb compiler

```
npm install -g drpc_dweb
drpc_dweb services.proto --rpc=rpc.js --messages=rpc-messages.js
npm install --save drpc_dweb-runtime # make sure to add this to your package.json
```

That's it!

The above produces two files, `rpc.js` and `rpc-messages.js`.
Now you can run an RPC server and client like so:

``` js
const MyRPC = require('./rpc')

// a server
const server = MyRPC.createServer(function (client) {
  client.example.onRequest({
    async echo ({ value }) {
      return { value: 'echo: ' + value }
    }
  })
})

await server.listen('/tmp/test.sock')

// a client
const client = MyRPC.connect('/tmp/test.sock')

const { value } = await client.example.echo({ value: 'hello world!'})
console.log(value) // 'echo: hello world'
```

The client object in the server and that's returned from connect implements the same API
so you can handle requests in both the server and client, depending on your needs!

To destroy a client do:

```js
client.destroy()
```

And to close a server and all open connections do:

```js
await server.close()
```

If your request handler throws an error it is forward to the client using the following schema

```proto
message RPCError {
  required string message = 1;
  optional string code = 2;
  optional int32 errno = 3;
  optional string details = 4;
}
```

And if your rpc method does not return a value you can use the `Void` type in the definition.

## License

MIT

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