The response must contain result or error, but both Members must not. Batch requestFinally, I made it clear how to perform this batch request, that is, to wrap multiple request objects in an array in a request. For example, package five requests:
--> [ {"jsonrpc": "2.0", "method": "sum", "params": [1,2,4], "id": "1"}, {"jsonrpc": "2.0", "method": "notify_hello", "params": [7]}, {"jsonrpc": "2.0", "method": "subtract", "params": [42,23], "id": "2"}, {"foo": "boo"}, {"jsonrpc": "2.0", "method": "foo.get", "params": {"name": "myself"}, "id": "5"}, {"jsonrpc": "2.0", "method": "get_data", "id": "9"} ]<-- [ {"jsonrpc": "2.0", "result": 7, "id": "1"}, {"jsonrpc": "2.0", "result": 19, "id": "2"}, {"jsonrpc": "2.0", "error": {"code": -32600, "message": "Invalid Request"}, "id": null}, {"jsonrpc": "2.0", "error": {"code": -32601, "message": "Method not found"}, "id": "5"}, {"jsonrpc": "2.0", "result": ["hello", 5], "id": "9"} ]
The Specification defines that all requests should be executed concurrently, and the return order is not guaranteed. The client uses the id to match the corresponding request and response. In addition, if an error occurs during request processing, a unified error message is returned (that is, the failure is not distinguished, and all errors are considered as failures ). This design seems to be for consideration of transactions, but it should be troublesome in general use cases.
Error objectThe improved error mechanism is that the error becomes a clearly defined object. There are three attributes: