how to support jsonrpc2.0 batch
sighWang opened this issue · comments
Ximing Wang commented
I have call jsonrpcserver with valid Batch, But there is error: { code: -32600, message: 'Invalid Request' }
return to me
Shogo Wada commented
Thanks for the catch. It doesn't support bulk requests as of now but let me add it!
Shogo Wada commented
I think it actually requires a breaking change, so let me think about it for a while.
In the meantime, you can workaround it by doing something like this:
const jsonRPCServer = new JSONRPCServer();
app.post("/json-rpc", async (req, res) => {
const request = req.body;
if (Array.isArray(request)) {
const responses = await Promise.all(request.map(request => jsonRPCServer.receive(request)));
res.json(responses);
} else {
const response = await jsonRPCServer.receive(request);
res.json(response);
}
});
Shogo Wada commented