Revision 981e0168

b/doc/rapi.rst
72 72
.. _RFC2617: http://tools.ietf.org/rfc/rfc2617.txt
73 73

  
74 74

  
75
A note on JSON as used by RAPI
76
++++++++++++++++++++++++++++++
77

  
78
JSON_ as used by Ganeti RAPI does not conform to the specification in
79
:rfc:`4627`. Section 2 defines a JSON text to be either an object
80
(``{"key": "value", …}``) or an array (``[1, 2, 3, …]``). In violation
81
of this RAPI uses plain strings (``"master-candidate"``, ``"1234"``) for
82
some requests or responses. Changing this now would likely break
83
existing clients and cause a lot of trouble.
84

  
85
.. highlight:: ruby
86

  
87
Unlike Python's `JSON encoder and decoder
88
<http://docs.python.org/library/json.html>`_, other programming
89
languages or libraries may only provide a strict implementation, not
90
allowing plain values. For those, responses can usually be wrapped in an
91
array whose first element is then used, e.g. the response ``"1234"``
92
becomes ``["1234"]``. This works equally well for more complex values.
93
Example in Ruby::
94

  
95
  require "json"
96

  
97
  # Insert code to get response here
98
  response = "\"1234\""
99

  
100
  decoded = JSON.parse("[#{response}]").first
101

  
102
Short of modifying the encoder to allow encoding to a less strict
103
format, requests will have to be formatted by hand. Newer RAPI requests
104
already use a dictionary as their input data and shouldn't cause any
105
problems.
106

  
107

  
75 108
PUT or POST?
76 109
------------
77 110

  

Also available in: Unified diff