Class BaseJsonRpcServer

This is a JSON RPC server that conforms to the JSON RPC 2.0 spec as documented at https://www.jsonrpc.org/specification

BaseJsonRpcServer

Constructors

  • Constructs a BaseJsonRpcServer server and returns it. Listens on localhost:8080 by default, on both IPv4 and IPv6 To listen only on IPv4, override onBeforeListening and call dns.setDefaultResultOrder('ipv4first'); To listen only on IPv6, if both IPv4 and IPv6 is enabled, just pass "localhost" to the host parameter

    Parameters

    • Optionalhost: string = "::"

      The IP address/hostname to listen on

    • Optionalport: number = CDefaultPort

      The port number to listen on

    Returns BaseJsonRpcServer

    BaseJsonRpcServer

Properties

mExpressServer: Express
mHttpTerminator: undefined | HttpTerminator
mJsonRpcServer: JSONRPCServer<void>
mListeningHost: string
mListeningPort: number
mRequest: undefined | Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>

Only valid when processing a request

mResponse: undefined | Response<any, Record<string, any>>

Only valid when processing a request

mServer: undefined | Server

Accessors

  • get listeningPath(): string
  • Returns the path on which to listen to requests for. Override to listen on another path.

    Returns string

    path on which to listen to requests for

Methods

  • Allows descendants to do something after class construction

    Returns void

    void

  • Creates an Invalid Request JSON RPC Error response.

    Parameters

    • request: any

    Returns JSONRPCErrorResponse

    Invalid Params JSON RPC response

  • Calls this.onParseError If onParseError doesn't handle the error, doParseError will send a JSON RPC Error response if the error is a parsing error, or pass the error up to the next middleware to handle

    Parameters

    Returns void

    Invalid Request JSON RPC Error exception

  • Handles a single or a batch JSON RPC request.

    Parameters

    • request: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>
    • response: Response<any, Record<string, any>>

    Returns Promise<void>

  • Returns a JSON parse error during express.json parsing

    Parameters

    • aExpress: Express

    Returns void

  • Error listener for JSON RPC, override to handle. Called when an error occurred during the JSON RPC method call. Do not throw an exception within this method

    Parameters

    • message: string
    • data: unknown

    Returns void

  • Starts listening for RPC requests

    Parameters

    • Optionalport: number

    Returns Promise<void>

  • This is called before the JSON RPC server starts listening on the port Override this, for example, to listen just on IPv4 by calling dns.setDefaultResultOrder('ipv4first');

    Returns void

  • Called when there's a parsing error. The overridden method should create a JSON RPC Error response and send it using response.send(err_response) If the error is not handled, this class will return an error

    Parameters

    Returns void

  • Creates an Invalid Params JSON RPC Error exception and sends it.

    Parameters

    • Optionaldata: any

    Returns void

  • Creates an Invalid Request JSON RPC Error exception and sends it.

    Parameters

    • Optionaldata: any

    Returns void

  • Stops the RPC server. This can be called by a RPC call or by the app itself

    Returns Promise<void>

  • Waits for the server to starts listening before returning. Override to disable this

    Returns Promise<void>