Hi,
> 1. It seems that most (all?) implementations of JSON-RPC 2.0 are assuming
> HTTP as the transport
no, they don't, and JSON-RPC 2.0 explicitely does not depend on HTTP.
I'm using JSON-RPC 2.0 over TCP and Unix Domain Sockets, and my Python-
implementation will soon support multiple JSON-RPC-requests per connection
and JSON-RPC over netstrings.
AFAIK, Kamailio also uses JSON-RPC over netstrings.
> there are requirements of HTTP that would be useful to specify in order to
> properly create inter-operable services, e.g., what content type to use
> (application/json? nothing?), what to status code to return for a
> Notification Request (204 or 200?), etc. Is there such a specification (or
> "sub-specification", not sure how that would be classified)?
There is an old JSON-RPC-over-HTTP-draft (
http://www.simple-is-better.org/json-rpc/jsonrpc20-over-http.html),
but I think this draft has some flaws, especially the mapping of errors
(and so mixing JSON-RPC and HTTP) is very ugly in my opinion.
I would suggest (and would write a JSON-RPC-over-HTTP-spec), to:
- simply tunnel JSON-RPC through HTTP POST
- Content-Type: I would suggest "application/json" or maybe "application/json-rpc".
Opinions?
- Status-Codes:
- 200 if HTTP succeeded
(Both for JSON-RPC-Responses and JSON-RPC-Errors;
There should be *no* error-mapping between JSON-RPC-Errors and HTTP errors!)
- 200 or 204 as answer to JSON-RPC Notifications.
- HTTP-error-code if HTTP failed
- HTTP GET is discouraged.
If *really* needed, we may specify that a JSON-RPC-RPC request may be
encoded in a URL in URL-Encoded form.
> 2. I see that some (many?) implementations of 2.0 don't implement every
> piece, the batch is the typical one left out. It's unclear to me whether
> the Batch capability is a requirement of the server.
I'm currently not sure. I thought that it normally should be implemented,
but may be omitted in special circumstances, in the sense of "SHOULD"
of RFC 2116 (
http://www.ietf.org/rfc/rfc2119.txt). But I'm not sure if
that was still the case when JSON-RPC 2.0 was released.
> I ask because I'd rather not implement Batch (because it
> requires me to detect whether I'm getting a JSON block, or an array of JSON
> blocks, which isn't trivial).
Really? Since you have to de-serialize the JSON-string, it should be
easy to detect if it is an JSON-array or JSON-object.
> 3. With the Batch call, any JSON objects in the array that have errors will
> be represented in the response with an Error Object. It'd be nice if, for
> Batch at least, the Error Object included the Request Object contents, if
> there's no ID for the Request, or the ID if one exists.
The Error-Object always contains the id of the Request (as long as the
id could be extracted from the Request), and the id should be used to
match Responses to the Requests. So, if you want to match Errors to
Requests, you should use appropriate ids.
Adding the Request to the Error-Object may be an option, but this is
implementation-dependent, and I'm not sure if we should recommend this
behaviour in the spec.
Roland