Samples

Description samples for testing.

Using cURL

To test OpenAPI, cURL is useful.

cURL Site : https://curl.haxx.se/

cURL options :

-X COMMAND, --request COMMAND
The request command to use. In the context of the REST API, use GET, POST, PUT or DELETE.
Example: -X GET

-H LINE, --header LINE
HTTP header to include with the request. Use multiple header options if more than one header is required.
Example: -H "Accept: application/json" -H "Content-Type: application/json"

-u USERNAME:PASSWORD, --user USERNAME:PASSWORD
The username and password of the Red Hat Enterprise Virtualization user. This attribute acts as a convenient replacement for the Authorization: header.
Example: -u admin@internal:p@55w0rd!

-k, --insecure Allow connections to SSL sites without certs (H)
--interface INTERFACE Use network INTERFACE (or address)

--cacert CERTIFICATE
The location of the certificate file for SSL communication to the REST API. The certificate file is saved locally on the client machine. Use the -k attribute to bypass SSL. See Chapter 2, Authentication and Security for more information on obtaining a certificate.
Example: --cacert ~/Certificates/rhevm.cer

-d BODY, --data BODY
The body to send for requests. Use with POST, PUT and DELETE requests. Ensure to specify the Content-Type: application/json header if a body exists in the request.
Example: -d "<cdrom><file id='rhel-server-6.0-x86_64-dvd.iso'/></cdrom>"


Examples

The following examples show how to adapt REST requests to cURL command syntax:

GET request

The following GET request lists the virtual machines in the vms collection. Note that a GET request does not contain a body.
GET /openapi/1/channels?skey=34a52b3 HTTP/1.1
Accept: application/json

Adapt the method (GET), header (Accept: application/json) and URI (http://server-ip:server-port/openapi/1/channels?skey=34a52b3) into the following cURL command:

$ curl -k -X GET -H "Accept: application/json;charset=UTF-8" https://server-ip:server-port/openapi/1/channels?skey=34a52b3

An json representation of the channel collection displays.


POST request

The following POST request creates a virtual machine in the vms collection. Note that a POST request requires a body.
POST /openapi/1/channels?skey=34a52b3 HTTP/1.1
Accept: application/json
Content-type: application/json;charset=UTF-8

{
    "no" : 123,
    "name": "abc",
    "description":"this is a good channel.",
    "notification":"welcome."
}

Adapt the method (POST), headers (Accept: application/json and Content-type: application/json), URI (http://server-ip:server-port/openapi/1/channels?skey=34a52b3) and request body into the following cURL command:

$ curl -k -X POST -H "Accept: application/json" -H "Content-type: application/json;charset=UTF-8" -d "{ \"no\" : 123, \"name\": \"abc\", \"description\":\"this is a good channel.\" \"notification\":\"welcome.\" }" https://server-ip:server-port/openapi/1/channels?skey=34a52b3

The REST API creates a new channel and displays an json representation of the resource.


PUT request

The following PUT request updates the memory of a virtual machine resource. Note that a PUT request requires a body.
PUT /openapi/1/channels/23?skey=34a52b3 HTTP/1.1
Accept: application/json
Content-type: application/json;charset=UTF-8

{
    "name": "abc"
}

Adapt the method (PUT), headers (Accept: application/json and Content-type: application/json), URI (http://server-ip:server-port/openapi/1/channels/23?skey=34a52b3) and request body into the following cURL command:

$ curl -k -X PUT -H "Accept: application/json" -H "Content-type: application/json;charset=UTF-8" -d "{ \"name\": \"abc\" }" https://server-ip:server-port/openapi/1/channels/23?skey=34a52b3

The REST API updates the channel with a new information.


DELETE request

The following DELETE request removes a virtual machine resource.
DELETE /openapi/1/channels/23?skey=34a52b HTTP/1.1

Adapt the method (DELETE) and URI (http://server-ip:server-port/openapi/1/channels/23?skey=34a52b3) into the following cURL command:

$ curl -k -X DELETE https://server-ip:server-port/openapi/1/channels/23?skey=34a52b3

The REST API removes the channel. Note the Accept: application/json request header is optional due to the empty result of DELETE requests.



Samples

The following examples show how to adapt ProPTT2 requests to cURL command syntax:

Server

$ curl -k -X POST -H "Accept: application/json" -H "Content-type: application/json;charset=UTF-8" -d "{ \"id\" : \"aa@aa.com\", \"hid\" : 1 }" https://server-ip:server-port/openapi/1/server

Auth

$ curl -k -X POST -H "Accept: application/json" -H "Content-type: application/json;charset=UTF-8" -d "{ \"id\" : \"aa@aa.com\", \"hid\" : 1 , \"authKey\":\"aba52c74fcbe6f1c0c6df5ae9eca312ce4124c2e2062dd4863e4aa9f1b275a2fec4cb613e81dd4f7027691224e141167eacfe19d686ebf47b067a7123745f5fa\"}" https://server-ip:server-port/openapi/1/auth

Get Channel List

$ curl -k -X GET -H "Accept: application/json" -H "Content-type: application/json;charset=UTF-8" "https://server-ip:server-port/openapi/1/channels?id=aa@aa.com&hid=1&skey=aba52c74fcbe6f1c0c6df5ae9eca312ce4124c2e2062dd4863e4aa9f1b275a2fec4cb613e81dd4f7027691224e141167eacfe19d686ebf47b067a7123745f5fa"



References

http://curl.haxx.se/docs/manual.html

https://access.redhat.com