JSONRPC request with no 'method' but with 'id'
A request like this, {"jsonrpc": "2.0", "params": [42, 23], "id": 1}. Should we send back a error response with id?
If I understand the JSON-RPC 2.0 specification correctly, when a request is missing the mandatory method field, the response should indicate an invalid request error as shown below.
Request:
{"jsonrpc": "2.0", "params": [42, 23], "id": 1}
Response:
{"jsonrpc": "2.0", "id": 1, "error": {"code": -32600, "message": "Invalid Request"}}
I have some changes in a fork of this repo which relate to error messages in the mjson jsronrpc handler. I will consider making a pull request.
I have the same understand with you. As you show, if a request has the correct 'id' item, the response will also has a correct 'id' item, no matter if the request has a 'method' item. But if I use the mjson correctly, now the response will not response with the correct request 'id' item. Request:
{"jsonrpc": "2.0", "params": [42, 23], "id": 1} now Response:
{"jsonrpc": "2.0", "error": {"code": -32600, "message": "Invalid Request"}, "id": null} or {"jsonrpc": "2.0", "error": {"code": -32600, "message": "Invalid Request"}}
expect Response: {"jsonrpc": "2.0", "id": 1, "error": {"code": -32600, "message": "Invalid Request"}}
Sorry, The new commit 'https://github.com/cesanta/mjson/pull/61' seems fixed this issues, thanks a lot.