3.3.3 • Published 2 years ago

rpc v3.3.3

Weekly downloads
15
License
ISC
Repository
github
Last release
2 years ago

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 } );
3.3.3

2 years ago

3.3.2

2 years ago

3.3.1

2 years ago

3.3.0

2 years ago

3.1.2

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.1.0

3 years ago

2.0.0

3 years ago

1.0.8

11 years ago

1.0.7

12 years ago

1.0.6

12 years ago

1.0.5

12 years ago

1.0.4

12 years ago

1.0.3

12 years ago

1.1.0

13 years ago

1.0.0

13 years ago