# rpc

> Connect/Express middleware that makes handling API calls easier

Latest version **3.3.3** (published 2022-07-13) · ISC license · 0 weekly downloads

## Install

```sh
npm install rpc
pnpm add rpc
yarn add rpc
bun add 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 | 3.3.3 |
| Published | 2022-07-13 |
| First published | 2011-09-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 3.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Joe Hitchens |
| Maintainers | sleeplessinc |

## Links

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

## Dependencies (5)

- [cors](https://npm.io/package/cors.md) ^2.8.5
- [connect](https://npm.io/package/connect.md) ^3.7.0
- [sleepless](https://npm.io/package/sleepless.md) ^5.2.3
- [body-parser](https://npm.io/package/body-parser.md) ^1.19.0
- [compression](https://npm.io/package/compression.md) ^1.7.4

## Recent versions

- 3.3.3 (latest) — 2022-07-13
- 3.3.2 — 2022-07-13
- 3.3.1 — 2022-05-15
- 3.3.0 — 2022-05-12
- 3.1.2 — 2021-10-25
- 3.0.2 — 2021-05-07
- 3.0.1 — 2021-05-07
- 3.0.0 — 2021-04-27
- 2.1.0 — 2021-04-27
- 2.0.0 — 2021-04-27
- 1.0.8 — 2013-10-17
- 1.0.7 — 2012-01-29
- 1.0.6 — 2012-01-29
- 1.0.5 — 2011-12-01
- 1.0.4 — 2011-12-01
- … 3 more at https://npm.io/package/rpc/versions

## README

# rpc

## Setup

	npm install rpc

## Usage

	app = require( "connect" )()
	url_path = "/api/"					// The url path prefix to watch for and handle
	api_path = "/disk/path/to/module"	// location of handler module
	app.use( require( "rpc" )( url_path api_path ) )

## API handler

Your API handler should be a module that can be loaded with require()
and should look something like this:

	module.exports = function( input, okay, fail ) {
		let action = input.action
		if( action == "ping" ) {
			okay( "pong" );
		} else {
			fail( "Unrecognized action: " + action );
		}
	}

The JSON response to the browser will look something like this if
you call okay():

	{ error: null, data: "pong" }

or this if you call fail():

	{ error: "Unrecognized action: foo", data: null }


## Options

To let your api handle calls from other domains:

	require( "rpc" )( url_path, api_path, { cors: true } );

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