koa-jayson-rpc
koa json rpc powered by jayson
Install
$ npm i koa-jayson-rpc --save
API
const Rpc =
rpc = new Rpc(options)
options.server
new Rpc
with a jayson.Server
instance
options.methods
new Rpc
with a methods
map same as jayson.Server(methods)
options.methodsDir
& options.methodsDirOptions
new Rpc
with a methods
map load from methodsDir
,
and methodsDirOptions
passed to require-directory
module
app.use(rpc)
the
rpc
instance can be used as koa middleware or handler
koa-mount
use use koa-mount
if you need server work on the /jsonrpc
path
const Koa = const mount = const Rpc = const app = const rpc = methodsDir: 'some-directory'app
use impress-router
const setupKoaApp = { const Koa = const Router = const app = const router = router app app 'extended' // post body const bodyParser = app return app} { const rpc = methodsDir: __dirname + '/fixtures/server' const app = // use rpc middleware appall'/jsonrpc' rpc appall'/jsonrpc/:method' rpc const server = app let json json = await jsonresultshould // use params.method json = await jsonresultshould}
Notice
method
¶ms
&id
&jsonrpc
: orderctx.params
>ctx.request.body
>ctx.query
- use
koa-qs
for passObject params
orArray params
withGET
requestArray
:params[]=1¶ms[]=2
Array
:params[0]=1¶ms[1]=2
Object
:params[name]=1¶ms[age]=2
Changelog
License
the MIT License http://magicdawn.mit-license.org