Describe the REST API and demonstrate how to use the REST API explorer
Understanding REST API
REST API is also known as Web Services API because behind the scenes, REST API calls are nothing but HTTP requests used to retrieve information from, or making changes to, the cluster.
Response Codes
- In response to an HTTP request, the server (cluster) returns a HTTP response which carries a Response Code.
- The response code tells the client the status of the requested operation.
- More information on response codes here.
Uniform Resource Identifier (URI)
- An URI defines the path to reach a resource or resources on the server (cluster).
- This path is made up of the Base Path + Relative Path.
- All resources reside under the same base path which is /PrismGateway/Services/REST/v2.0/
- All resources reside in their respective relative paths.
- For instance, all VMs reside in /PrismGateway/Services/REST/v2.0/vms
Message Body
All HTTP requests have a similar structure
- An HTTP Request begins with:
- A Request Line
- One or more Request Headers, and
- The Message Body (may be empty).
- A GET Request Line looks like this:
- GET /vms HTTP/1.1
- It is followed by some HTTP headers and an empty message body.
- All HTTP Responses have a similar structure also.
- An HTTP Response begins with a Status Line like:
- HTTP/1.1 200 OK
- It is followed with one or more HTTP headers and a message body.
- In the case of the response to GET /vms, the Message Body contains the VM’s configuration in JSON format.
- A POST Request Line looks similar:
- POST /vms/ HTTP/1.1
- It is followed by some HTTP Headers and a Message Body which defines the VM configuration in JSON format.
API explorer
The HTTP verbs comprise a major portion of our “uniform interface” constraint and provide us the action counterpart to the noun-based resource. The primary or most-commonly-used HTTP verbs (or methods, as they are properly called) are POST, GET, PUT, PATCH, and DELETE. These correspond to create, read, update, and delete (or CRUD) operations, respectively. There are a number of other verbs, too, but are utilized less frequently. Of those less-frequent methods, OPTIONS and HEAD are used more often than others.
The Nutanix REST APIs allow you to create scripts that run system administration commands against the Nutanix cluster. The API enables the use of HTTP requests to get information about the cluster as well as make changes to the configuration. Output from the commands are returned in JSON format.
There are two versions of the Nutanix REST API.
- v1: The original Nutanix REST API.
- v2: An update of the v1 API. Users of the v1 API are encouraged to migrate to v2.
The REST API Explorer displays a list of the cluster objects that can be managed by the API. Each line has four options:
- Show/Hide: Expand or reduce the detail shown for the object
- List Operations: Show all operations that can be run on this object
- Expand Operations: Show the detailed view of the operations that can be run on this object