2.6.3.2 Python

Building on the authentication code provided in Section 2.2, “How do I Authenticate?” we continue to use the requests.Session object to send a GET request to list all server details to the REST API. The response content is in JSON format. Fortunately, the Requests library is capable of decoding JSON automatically. This means that you can treat the content returned by the HTTP request as a native Python data object:

 ...
 r=s.get(baseUri+'/Server')
 for i in r.json():
       # do something with the content
       print '{name} is {state}'.format(name=i['name'],state=i['serverRunState'])
 ...

The baseUri specified above is based on the variable that we set during authentication as described in Section 2.2, “How do I Authenticate?” and we have appended the Server objecttype to it to notify the API of the type of data that we are requesting.