Skip to content

Latest commit

 

History

History
35 lines (29 loc) · 712 Bytes

README.md

File metadata and controls

35 lines (29 loc) · 712 Bytes

nestjs-json-rpc

Nestjs JSON RPC 2.0 Controller

Install

yarn add nestjs-json-rpc
npm add nestjs-json-rpc

Usage

import {
  JsonRpcController,
  JsonRpcMethod,
  IJsonRpcId,
  IJsonRpcParams
} from 'nestjs-json-rpc'

@JsonRpcController('/jsonrpc/endpoint')
export class SomeJsonRpcController {
  @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'
  }
} 

Specification

https://www.jsonrpc.org/specification