@qiwi/json-rpc
v1.0.14
Published
JSON RPC 2.0 facade
Downloads
20
Readme
@qiwi/json-rpc
JSON RPC 2.0 Controller
Install
yarn add @qiwi/json-rpc
npm add @qiwi/json-rpc
Usage
import {
JsonRpcMiddleware,
JsonRpcMethod,
IJsonRpcId,
IJsonRpcParams
} from '@qiwi/json-rpc'
@JsonRpcMiddleware()
export class SomeJsonRpcMware {
@JsonRpcMethod('some-method')
doSomething(@JsonRpcId() id: IJsonRpcId, @JsonRpcParams() params: IJsonRpcParams) {
const {foo} = params
if (foo === 'bar') {
return new JsonRpcError(-100, '"foo" param should not be equal "bar"')
}
return 'ok'
}
}
const jsonRpcMware = new SomeJsonRpcMware().middleware
app.use('/rpc', jsonRpcMware)