diff --git a/doc/rapi.rst b/doc/rapi.rst index fcf955abdb2421e8ceca1635c4fc5fd0823c06ba..b9fe651d9a2848619828d760cb71467f8566d716 100644 --- a/doc/rapi.rst +++ b/doc/rapi.rst @@ -72,6 +72,39 @@ HTTP Basic authentication as per RFC2617_ is supported. .. _RFC2617: http://tools.ietf.org/rfc/rfc2617.txt +A note on JSON as used by RAPI +++++++++++++++++++++++++++++++ + +JSON_ as used by Ganeti RAPI does not conform to the specification in +:rfc:`4627`. Section 2 defines a JSON text to be either an object +(``{"key": "value", β¦}``) or an array (``[1, 2, 3, β¦]``). In violation +of this RAPI uses plain strings (``"master-candidate"``, ``"1234"``) for +some requests or responses. Changing this now would likely break +existing clients and cause a lot of trouble. + +.. highlight:: ruby + +Unlike Python's `JSON encoder and decoder +<http://docs.python.org/library/json.html>`_, other programming +languages or libraries may only provide a strict implementation, not +allowing plain values. For those, responses can usually be wrapped in an +array whose first element is then used, e.g. the response ``"1234"`` +becomes ``["1234"]``. This works equally well for more complex values. +Example in Ruby:: + + require "json" + + # Insert code to get response here + response = "\"1234\"" + + decoded = JSON.parse("[#{response}]").first + +Short of modifying the encoder to allow encoding to a less strict +format, requests will have to be formatted by hand. Newer RAPI requests +already use a dictionary as their input data and shouldn't cause any +problems. + + PUT or POST? ------------