Operations are triggered through standard HTTP methods on a resource’s URL. A particular URL generally points to an entity or an entities collection. Given the situation, HTTP methods usually have the same effect: a POST on a collection creates a new entity, a DELETE on an entity removes it from its collection, etc.
The URL for a collection ‘A’ always has the form https://my.comodit.com/api/A where https://my.comodit.com/api is the URL of ComodIT’s API. On such URL, the following methods are usually defined:
In order to list the entities of the collection ‘A’, just issue an HTTP request with the GET method on the collection URL:
curl -X GET http://my.comodit.com/api/A --user admin
This will return a JSON representation of the collection (content type application/json):
{
"count": 1,
"offset": 0,
"total": 1,
"items": [
{
...
},
...
]
}
The ‘items’ array Such a result always has the following four fields:
In order to create an entity, you must provide the representation of the new entity using the HTTP POST method. With curl, you could do this with the following command. Note that you must specify the content type of the request to be ‘application/json’.
curl -X POST -H"Content-Type: application/json" -d @entity.json http://my.comodit.com/api/A --user comodit
Where entity.json is a file containing the JSON representation of the entity. The system replies with a 200 HTTP status code and the JSON representation of the created entity.
The URL of an entity ‘a’ part of a collection ‘A’ always has the form https://my.comodit.com/api/A/a. You can find this URL in the documentation of each entity. On such URL, the following methods are usually defined:
In order to get the representation of a resource, just issue an HTTP request with the GET method:
curl -X GET http://my.comodit.com/api/A/a --user comodit
This will return a JSON representation of the entity (content type application/json):
{
...
}
In order to modify an entity, you must provide the modified representation using the HTTP PUT method. With curl, you could do this with the following command. Note that you must specify the content type of the request to be application/json.
curl -X PUT -H "Content-Type: application/json" -d @entity.json http://my.comodit.com/api/A/a --user comodit
where entity.json is a file containing the JSON representation of the entity. The system replies with a 200 HTTP status code and the representation of the updated entity.
In order to delete an entity, just issue an HTTP request with the DELETE method:
curl -X DELETE http://my.comodit.com/api/organizations/A/a --user comodit
The server replies with a HTTP 200 status code.
Once deleted, trying to read the entity will result in an HTTP 404 status code and a developer friendly error message in JSON:
{
"error": ["No host with name HAL"],
"status": 404
}
where error field is an array of error messages and status the HTTP error code.
Some collections are defined in the context of a particular entity. For example, let an entity ‘a’ be part of collection ‘A’ and have a collection ‘B’ containing an entity ‘b’. The URL to collection ‘B’ is then:
http://my.comodit.com/api/A/a/B
Therefore, entity ‘b’ is accessed using URL:
http://my.comodit.com/api/A/a/B/b
Of course, operations defined in previous sections apply in the same way.
For readability’s sake, URL may be shortened. For example URL:
http://my.comodit.com/api/A/a/B/b
becomes:
/A/a/B/b
Finally, relative URLs to generic sub-collections defined for different entity types may be defined. For example, in the context of entity ‘a’, the URL to entity ‘b’ may be written:
B/b
To summarize, following notations are equivalent (in the context of entity ‘a’):
http://my.comodit.com/api/A/a/B/b
/A/a/B/b
B/b
2016 © ComodIT. All Rights Reserved. Privacy Policy | Terms of Service