delphirtl • Docs
delphirtl / 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
new BaseJsonRpcServer(
host?,port?):BaseJsonRpcServer
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
• host?: string = "::"
The IP address/hostname to listen on
• port?: number = CDefaultPort
The port number to listen on
BaseJsonRpcServer
protectedmExpressServer:Express
protectedmHttpTerminator:undefined|HttpTerminator
protectedmJsonRpcServer:JSONRPCServer<void>
protectedmListeningHost:string
protectedmListeningPort:number
protectedmRequest:undefined|Request<ParamsDictionary,any,any,ParsedQs,Record<string,any>>
Only valid when processing a request
protectedmResponse:undefined|Response<any,Record<string,any>>
Only valid when processing a request
protectedmServer:undefined|Server<typeofIncomingMessage, typeofServerResponse>
get listeningPath():
string
Returns the path on which to listen to requests for. Override to listen on another path.
string
path on which to listen to requests for
protectedaddRPCMethods():void
Adds all necessary JSON RPC methods to this.mJsonRpcServer
void
protectedafterConstruction():void
Allows descendants to do something after class construction
void
void
protectedcreateInvalidParams(data?):JSONRPCErrorException
Creates an Invalid Params JSON RPC Error exception, with the message as Invalid Params. The caller must throw the return of this call.
• data?: any
Invalid Params JSON RPC Error exception
protectedcreateInvalidParamsMessage(message,data?):JSONRPCErrorException
Creates an Invalid Params JSON RPC Error exception, with the given message. The caller must throw the return of this call.
• message: string
• data?: any
Invalid Params JSON RPC Error exception
protectedcreateInvalidRequest(data?):JSONRPCErrorException
Creates an Invalid Request JSON RPC Error exception, with the message as Invalid Params. The caller must throw the return of this call.
• data?: any
Invalid Request JSON RPC Error exception
protectedcreateInvalidRequestResponse(request):JSONRPCErrorResponse
Creates an Invalid Request JSON RPC Error response.
• request: any
JSONRPCErrorResponse
Invalid Params JSON RPC response
protectedcreateMethodNotFoundResponse(request):JSONRPCErrorException
Creates a Method not found JSON RPC Error response, with the message as Invalid Params. The caller must throw the return of this call.
• request: any
Invalid Request JSON RPC Error exception
protecteddoParseError(err,req,res,next):void
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
• err: any
• req: Request
• res: Response
• next: NextFunction
void
Invalid Request JSON RPC Error exception
echo(
params):any
• params: any
any
protectedhandleRequest(request,response):Promise<void>
Handles a single or a batch JSON RPC request.
• request: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>
• response: Response<any, Record<string, any>>
Promise<void>
protectedimplementedRPCMethods():SimpleJSONRPCMethod<void>[]
Returns RPC methods implemented by the server Override to return an array of RPC methods implemented.
SimpleJSONRPCMethod<void>[]
array of RPC methods implemented
protectedinitExpress():Express
Initializes the Express server and returns it
Express
protectedinitJsonRpcServer():JSONRPCServer<void>
Initializes the JSON RPC server and returns it
JSONRPCServer<void>
protectedinitParseErrorHandler(aExpress):void
Returns a JSON parse error during express.json parsing
• aExpress: Express
void
protectedJsonRpcErrorListener(message,data):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
• message: string
• data: unknown
void
listen(
port?):Promise<void>
Starts listening for RPC requests
• port?: number
Promise<void>
protectedlog(…data):void
• …data: any[]
void
protectedlogListeningMethods(methods):void
Displays the JSON RPC methods being listened to
• methods: SimpleJSONRPCMethod<void>[]
void
protectedonBeforeDispatchRequest(next,request,serverParams):JSONRPCResponsePromise
Called before every valid JSON body is dispatched, this doesn’t mean that the request is a valid JSON RPC call though. If the request is valid, the method should call next(request, serverParams) and return its result. If the request is invalid, it should throw an appropriate error.
• next: JSONRPCServerMiddlewareNext<void>
• request: JSONRPCRequest
• serverParams: undefined | void
protectedonBeforeListening():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’);
void
protectedonParseError(err,request,response):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
• err: any
• request: Request
• response: TSendHandler
void
protectedsendInvalidParams(data?):void
Creates an Invalid Params JSON RPC Error exception and sends it.
• data?: any
void
protectedsendInvalidRequest(data?):void
Creates an Invalid Request JSON RPC Error exception and sends it.
• data?: any
void
stop():
Promise<void>
Stops the RPC server. This can be called by a RPC call or by the app itself
Promise<void>
protectedstopListening():Promise<void>
Promise<void>
protectedwaitForServerListening():Promise<void>
Waits for the server to starts listening before returning. Override to disable this
Promise<void>
protectedwaitForServerStopListening():Promise<void>
Promise<void>