pavlov99 / json-rpc

🔁 JSON-RPC 1/2 transport implementation. Supports python 2/3 and pypy.
http://json-rpc.readthedocs.org
MIT License
464 stars 100 forks source link

Server issued notifications #93

Open ikv opened 6 years ago

ikv commented 6 years ago

I would like to push some notifications from the server down to the client. From the looks of it, json-rpc does not supports such use case, or does it?

pavlov99 commented 6 years ago

Hi, @ikv

This library's main purpose is to provide a protocol implementation and be as much server agnostic as possible. It does support "request-response" functionality via manager and provides optional backends for Django and Flask.

In your case, there is no API request "from outside" as the server sends notifications based on some internal event. That means that you do not need to use a large chunk (80%+) of this library. I would consider two cases:

  1. Use this library to make sure notifications are in a correct JSON-RPC format (regular or batch). The library provides some validation, data manipulation, and serialization mechanisms. Please take a look at JSONRPC20Response.

  2. Skip this library and manually create a JSON-RPC response object. Since it is created on the server side, you know it is in the right format. In this case, you don't need any format validation or exception handling on the server.

Please let me know what you think about it.

ikv commented 6 years ago

In your case, there is no API request "from outside" as the server sends notifications based on some internal event.

This is not the case. I need to do both: accept external requests and issue notifications.

For example, this protocol requires to push two different events (miming.set_target and mining.notify) after first call to mining.authorize.