Options
All
  • Public
  • Public/Protected
  • All
Menu

Class RpcEndpoint

JSON-RPC 2.0 endpoint class https://www.jsonrpc.org/specification

Hierarchy

  • RpcEndpoint

Index

Constructors

constructor

Properties

Private coerceRequestsToJsonRpc2

coerceRequestsToJsonRpc2: boolean

Whether to coerce requests without the 'jsonrpc' member to valid JSON-RPC 2.0 requests

Protected log

log: ILogger

Logger used to print log messages

Protected module

module: IRpcModule

Module whose methods can be called via the RPC endpoint

Protected path

path: string

Path the endpoint is registered at

Methods

Private checkMethodExistence

  • checkMethodExistence(method: string): void
  • Check whether the specified method exists

    throws

    Throws a 'Method not found' error if the method does not exist

    Parameters

    • method: string

      Method name to check

    Returns void

Protected execute

  • execute(method: string, params: any[]): Promise<any>
  • Execute the RPC

    Parameters

    • method: string

      Method to execute

    • params: any[]

      Parameters passed to the method invocation

    Returns Promise<any>

Private executeRpc

  • executeRpc(req: any, res: any, next: any): Promise<any>
  • Middleware for executing the RPC call as specified in the RPC request

    Parameters

    • req: any
    • res: any
    • next: any

    Returns Promise<any>

getPath

  • getPath(): string

register

  • register(server: Express): void
  • Register the RPC endpoint with the given Express server

    Parameters

    • server: Express

      Express server object

    Returns void

setLogger

Static coerceRequestsToJsonRpc2Middleware

  • coerceRequestsToJsonRpc2Middleware(req: any, res: any, next: any): any
  • Attempt to coerce each request to be a valid JSON-RPC 2.0 request:

    • Add 'jsonrpc': '2.0'
    • Add 'id': null if no 'id' member was provided, assuming the client is interested in the response

    Parameters

    • req: any
    • res: any
    • next: any

    Returns any

Static getRpcRequests

  • Convenience method that normalizes the request body by always returning an array of rpc requests, even if only one is specified (both is allowed by the RFC)

    Parameters

    • req: any

    Returns IRpcRequest[]

Static validateRequestBody

  • validateRequestBody(req: any, res: any, next: any): any
  • Check whether the incoming request body is a valid JSON-RPC 2.0 request object (terminate the request otherwise)

    Parameters

    • req: any
    • res: any
    • next: any

    Returns any