salt-api cherrypy Response as Array #67536
Replies: 4 comments
-
An example of this pattern can be found at https://jsonapi.org/format/#fetching-resources-responses specifies "A server MUST respond to a successful request to fetch a resource collection with an array of resource objects or an empty array ([]) as the response document’s primary data." The format of the response could be changed and maintain backwards compatibility by versioning the new version. A prefix of |
Beta Was this translation helpful? Give feedback.
-
This might be best done with a new outputter to avoid breaking existing interfaces. |
Beta Was this translation helpful? Give feedback.
-
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue. |
Beta Was this translation helpful? Give feedback.
-
Thank you for updating this issue. It is no longer marked as stale. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description of Issue
When you query salt-api for groups of items such as
jobs
orminions
, the api returns a JSON response that's formatted as a single object instead of an Array or List of those items.Setup
Configure salt-api according to the cherrypy documentation and query the
/jobs/
or/minions/
endpoints.Steps to Reproduce Issue
Once you query these endpoints, you'll see a response similar to these:
Notice the Jobs endpoint returns a document with key "return" that contains an array. This array doesn't contain an object per job, but instead returns a single massive object with all the jobs as top level keys in that single object. This means we can't marshal this JSON to a data structure that would allow discovery of the jobs in the response. You have to know the job id to know which key to grab from the single, large document.
A better jobs response would look like the following. We can now iterate through the array of objects, and identify the job based on the jid key. This also allows us to count the total number of jobs.
Here's a similar example using the
/minions/
endpoint.And a more ergonomic response:
Versions Report
Beta Was this translation helpful? Give feedback.
All reactions