On 6/22/23 09:26, Nick Couchman wrote:
On Thu, Jun 22, 2023 at 12:08 PM Najib . <aounina...@outlook.com> wrote:

Its really awesome that Guacamole can be called using REST API, this makes it 
incredibly powerful and flexible. However there some pain points and 
improvements possible

The connection and connection group response bodies are a  rather big JSON. 
They don’t use the array type and the keys contain the actual values of the 
connection identifier. Any JSON parser will panic trying to decipher them. Is 
there a reason why such JSON file is created for these two types whereas others 
respect proper JSON formatting? See below for what a better reponse body would 
look like.

Working backward:
* "Any JSON parser will panic trying to decipher them" - I don't think
so - in fact, these very REST API responses are used by the browser
itself to drive the web application. So there's at least one parser
that _does not_ currently choke on them :-). Also, there's nothing
wrong or non-standard about the JSON - it's perfectly valid, perfectly
legitimate JSON. If a JSON parser is choking on the response, then it
seems that it is unable to parse valid JSON, or simply does not have
the resources to handle it. Using the identifier simply makes it an
object, not an array - but it's still "good" JSON.
* "They don’t use the array type and the keys contain the actual
values of the connection identifier." - Yes, in fact, that's exactly
the reason it is implemented this way. That way, if you want to get a
specific connection or connection group, all you have to do is go get
the specific object and you don't have to loop through the entire
array looking for the correct identifier.

Najib, can you clarify further why object vs. array would be a substantial cause of difficulty for applications consuming the REST API?

As Nick notes above, there is a technical reason we prefer to return objects instead of arrays for responses that contain collections of uniquely-identified objects. Barring a solid technical reason to migrate to arrays, I would definitely be against changing the REST API in this way.

The only technical reasons that occur to me for an array being more ideal than an object in a REST API response would be:

* Cases where order is significant.
* Cases where objects do not have unique identifiers.

but neither of those would apply here.

- Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@guacamole.apache.org
For additional commands, e-mail: user-h...@guacamole.apache.org

Reply via email to