0.2.0 • Published 9 years ago

rpcinterface v0.2.0

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

rpcinterface

Build a rpc interface in your webapp or node app. Requires jQuery for promises on the web (via browserify).

Usage (with browserify/node)

var rpc = require('rpcinterface');

RPCInterface Methods

rpc = new RPCInterface()

Creates a new RPCInterface instance. Should be done at application start up.

rpc.addMethod(name, params, handler)

rpc.addMethod(name, handler)

rpc.addMethod(name, options)

Adds a new handler for method name. options should be an object that has handler and params keys. handler is a callback that is called with (parameters, deferred) when a new call is made for this method name. If params are not defined then no parameter checking is done.

params should be a hash like this example:

{
    email: {type: 'string', optional: false},
    password: {type: 'string', optional: false},
    name: {type: 'string', optional: false},
    phone: {type: 'number', optional: true}
}

If params is null (rather than an object or undefined) then the parameters object sent to the handler will be an empty object, guaranteed. Normally the passed object is validated but passed through as originally sent. This could cause issues if you're expecting an empty object since your method accepts no parameters but the caller sent extraneous parameters.

rpc.removeMethod(name)

Removes the handler for method name.

rpc.setPreProcessor(func)

Sets the pre-processor, which is called before the handler but after the request is validated. The func is sent (method, params, dfd). method is the string method name being called and params is the parameters object sent by the caller.

rpc.call(method, params)

Calls a method added by addMethod and sends along the passed params. Returns a deferred. Throws if params are invalid/missing for the method being called or if the method wasn't added. params can also be an array where the order of the values is based on the defined order when addMethod was called.

0.2.0

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago

0.0.11

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago