We have a HTTP RPC api for which all of the arguments are to be encoded using JSON. This works, but it actually does not feel very elegant to have a mix of MIME x-www-form-urlencoding and JSON in the body of the http post. I.e. the body might look like this:
POST /my/rpc/api/endpoint
foo={"x":123,"y":true}&bar=[1,2,3,4,5,6,7]
I have seen services that don’t use MIME at all and go for full json encoding. E.g:
POST /my/rpc/api/endpoint
{"foo":{"x":123,"y":true},"bar":[1,2,3,4,5,6,7]}
I think the latter solution looks much cleaner, however I am not quite sure if this is a violation of HTTP conventions and which implications this would have. Is this something to avoid? Would this make it harder to implement clients for example?
There’s nothing wrong with using JSON in the POST payload. What’s important is to use the proper internet media type, thus “application/json”, instead of “application/x-www-form-urlencoded”.