A tool for processing JSON-RPC requests and responses.
const JsonRpcEngine =let engine =
Build a stack of JSON-RPC processors by pushing middleware to the engine.
Requests are handled asynchronously, stepping down the stack until complete.
let request = id: 1 jsonrpc: '2.0' method: 'hello'engine// There is also a Promise signatureconst response = await engine
Middleware have direct access to the request and response objects.
They can let processing continue down the stack with
next(), or complete the request with
By passing a return handler to the
next function, you can get a peek at the result before it returns.
Engines can be nested by converting them to middleware using
const engine =const subengine =engine
If you require your middleware function to be
const createAsyncMiddleware =let engine =engine
async middleware do not take an
Instead, the request ends if the middleware returns without calling
next callback of
async middleware also don't take return handlers.
Instead, you can
When the execution of the middleware resumes, you can work with the response again.
You can freely mix callback-based and
Handle errors via
/* INCORRECT */engine/* CORRECT */engine
next() will detect errors on the response object, and cause
end(res.error) to be called.