Questo contenuto non è disponibile nella lingua selezionata.
7.2. Collections
7.2.1. Listing All Resources in a Collection Copia collegamentoCollegamento copiato negli appunti!
GET request on the collection URI obtained from the entry point.
GET /api/[collection] HTTP/1.1
Accept: application/xml
HTTP/1.1 200 OK
Content-Type: application/xml
<collection>
<resource id="resource_id" href="/api/collection/resource_id">
<name>Resource-Name</name>
<description>A description of the resource</description>
...
</resource>
...
</collection>
7.2.2. Listing Extended Resource Sub-Collections Copia collegamentoCollegamento copiato negli appunti!
Accept header includes the detail parameter.
GET /api/collection HTTP/1.1
Accept: application/xml; detail=subcollection
detail parameters:
GET /api/collection HTTP/1.1
Accept: application/xml; detail=subcollection1; detail=subcollection2
detail parameter that separates the sub-collection with the + operator:
GET /api/collection HTTP/1.1
Accept: application/xml; detail=subcollection1+subcollection2+subcollection3
| Collection | Extended Sub-Collection Support |
|---|---|
hosts | statistics |
bricks | statistics |
step | statistics |
Example 7.1. An request for extended statistics in the servers collection
GET /api/hosts HTTP/1.1
Accept: application/xml; detail=statistics
7.2.3. Searching Collections with Queries Copia collegamentoCollegamento copiato negli appunti!
GET request on a "collection/search" link results in a search query of that collection. The API only returns resources within the collection that satisfy the search query constraints.
GET /api/collection?search={query} HTTP/1.1
Accept: application/xml
HTTP/1.1 200 OK
Content-Type: application/xml
<collection>
<resource id="resource_id" href="/api/collection/resource_id">
...
</resource>
...
</collection>
7.2.3.1. Query Syntax Copia collegamentoCollegamento copiato negli appunti!
query with a GET request:
GET /api/collection?search={query} HTTP/1.1
Accept: application/xml
query template value refers to the search query the API directs to the collection. This query uses the same format as Red Hat Storage Console search query language:
(criteria) [sortby (element) asc|desc]
sortby clause is optional and only needed when ordering results.
| Collection | Criteria | Result |
|---|---|---|
volumes | type=REPLICATE | Displays a list of all replicate volumes |
events | severity>normal sortby time | Displays the list of all events with severity higher than normal and sorted by the time element values. |
events | severity>normal sortby time desc | Displays the list of all events with severity higher than normal and sorted by the time element values in descending order. |
query template to be URL-encoded to translate reserved characters, such as operators and spaces.
Example 7.2. URL-encoded search query
GET /api/events?search=severity%3Derror HTTP/1.1
Accept: application/xml
Important
7.2.3.2. Wildcards Copia collegamentoCollegamento copiato negli appunti!
Example 7.3. Wildcard search query for name=server*
GET /api/hosts?search=name%3Dserver* HTTP/1.1
Accept: application/xml
server, such as server-1, server-2, or server-data.
Example 7.4. Wildcard search query for name=s*1
GET /api/hosts?search=name%3D*1 HTTP/1.1
Accept: application/xml
s and ending with 1, such as server1 or server-1 .
7.2.3.3. Pagination Copia collegamentoCollegamento copiato negli appunti!
page command.
Example 7.5. Paginating resources
GET /api/collection?search=page%201 HTTP/1.1
Accept: application/xml
page value to view the next page of results.
GET /api/collection?search=page%202 HTTP/1.1
Accept: application/xml
page command also in conjunction with other commands in a search query. For example:
GET /api/collection?search=sortby%20element%20asc%20page%202 HTTP/1.1
Accept: application/xml
7.2.4. Creating a Resource in a Collection Copia collegamentoCollegamento copiato negli appunti!
POST request to the collection URI containing a representation of the new resource.
POST request requires a Content-Type: application/xml header. This informs the API of the XML representation in the body content as part of the request.
fault representation indicating the missing elements.
POST /api/collection HTTP/1.1
Accept: application/xml
Content-Type: application/xml
<resource>
<name>Resource-Name</name>
</resource>
HTTP/1.1 201 Created
Content-Type: application/xml
<resource id="resource_id" href="/api/collection/resource_id">
<name>Resource-Name</name>
...
</resource>
Location header in the response gives the URI of the queried resource. The response body contains either a complete representation, partial representation or no representation of the resource. It is recommended that clients rely only on fetching the representation via the URI in the response header.