for3st for3st - 14 days ago 4x
HTTP Question

What is the correct content-type header for Json RPC v2 over HTTP?

I know that JSON RPC is no hard spec, but I cannot find a proper solution on this. The question is what content-type is/are correct:

  1. content-type: application/json

  2. content-type: application/json-rpc

  3. both?

In the official (?) doc for v2 and v1 there is nothing about content-types only in this seemingly deprecated document about JSON rcp v1.2 there is the definition of (2) but optional (1).

By investigating the popular jsonRPC4J java lib that uses v2 spec I found in the client that they set (2):

* Prepares a connection to the server.
* @param extraHeaders extra headers to add to the request
* @return the unopened connection
* @throws IOException
protected HttpURLConnection prepareConnection(Map<String, String> extraHeaders)
throws IOException {

con.setRequestProperty("Content-Type", "application/json-rpc");

// return it
return con;

For me best practice would be to just accept both to be on the "safe" side?


After a quick google search I see others using application/json which is what I would have expected for JSON. Since the documentation doesn't specify, I imagine this could be hit or miss depending on the implementation of the server.

Maybe you could implement a routine that tried the other on a bad response? Not ideal, but the docs aren't helping you much.