Replies: 3 comments 21 replies
-
Also, to be very strict, |
Beta Was this translation helpful? Give feedback.
-
If I understand the JSON-RPC specification correctly, the distinction between requests and notifications lies within the client only. So, while it might make sense in some cases in the server implementation to know whether a response is required (e.g., to avoid computationally intense calculations), I'd rather want the server implementation to handle that part of the communication alone. |
Beta Was this translation helpful? Give feedback.
-
I think one can avoid introducing a API method for this. Consider this: @app.route("/", methods=["POST"])
def handler():
response = dispatch(...)
if response is None:
return Response(status_code=HTTP_204_NO_CONTENT)
else:
return to_json(response) # it must have been something we should reply to, error or not, and it has an Id. The empty string Ideas found here: fastapi/fastapi#717 If |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
There's one more concern with JSON-RPC -- you shouldn't always return a response.
There are two reasons a response should not be sent:
The question is how the developer API to handle this should look.
I'm thinking of a
should_respond
function which makes the decision for you based on the return value from dispatch, something like this (note synchronous protocols like http must return something)For async protocols something like:
Does this make sense? Would appreciate any thoughts.
Beta Was this translation helpful? Give feedback.
All reactions