# @fictorial/express-rpc

> Getting tired of REST and GraphQL and just want to expose some JavaScript functions to clients over HTTP?

Latest version **1.0.1** (published 2019-03-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install @fictorial/express-rpc
pnpm add @fictorial/express-rpc
yarn add @fictorial/express-rpc
bun add @fictorial/express-rpc
```

Provides the command `express-rpc`.

## 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.1 |
| Published | 2019-03-21 |
| First published | 2019-03-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 3.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Brian Hammond |
| Maintainers | fictorial |
| Keywords | express, rpc, json, http |

## Links

- npm: https://www.npmjs.com/package/@fictorial/express-rpc
- Repository: https://github.com/fictorial/express-rpc
- Homepage: https://github.com/fictorial/express-rpc#readme
- Issues: https://github.com/fictorial/express-rpc/issues
- npm.io page: https://npm.io/package/@fictorial/express-rpc

## Dependencies (5)

- [flat](https://npm.io/package/flat.md) ^4.1.0
- [debug](https://npm.io/package/debug.md) ^4.1.1
- [dotenv](https://npm.io/package/dotenv.md) ^7.0.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.11
- [express](https://npm.io/package/express.md) ^4.16.4

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.1 (latest) — 2019-03-21
- 1.0.0 — 2019-03-20

## README

# JSON-over-HTTP RPC server for Express

Getting tired of REST and GraphQL and just want to expose some JavaScript functions to clients over HTTP?

Me too!

```sh
npm i -g @fictorial/express-rpc
```

```sh
# optional; for PORT, etc.
# $EDITOR .env

express-rpc my_rpcs.js

# or when developing
# DEBUG=express-rpc node index.js ./example/my_rpcs.js
```

```JavaScript
// ./example/my_rpcs.js

module.exports = {
  greet: ({ name }) => {
    return { greeting: `Hello, ${name || 'anon'}` }
  }
}
```

```sh
curl -H 'Content-type: application/json' --data-binary '{ "name": "Brian" }' localhost:2999/rpc/greet
```

```
{ "greeting": "Hello, Brian" }
```

## Notes

The exported RPCs can be nested and then referenced by clients using familiar dot-notation
e.g. `localhost:2999/greetings.hello`, etc.

Exported functions can be `async`.

If your RPC throws the `Error` thrown is used in the response:
- `Error.code` for the HTTP status code; default: 500

- `Error.message` for the body of the response `{ error: { message: "..." }}`

`this` inside a handler is the `req` from Express.

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