Approaches to REST API (rest / v1)
API schema of request to REST
/rest/v1/<CHAPTER>/<RESOURCE_PATH>
-
v1
– partition backward compatibility version API; -
<CHAPTER>
– section name; -
<RESOURCE_PATH>
– the path in the resource tree to the endpoint, e.g./selectors/<SELECTOR_ID>/participants/<PARTICIPANT_ID>
.
-
Collection names in plural form (ang. plural);
-
Collections always contain elements of the same type;
-
Using HTTP Verbs for create/read/update/delete operations (CRUD).
POST collections
Creates a new resource in the collection and returns it in response to a request.
The new resource to be created is passed as a request body in JSON format (Content-Type: application/json
) or JSON in parameter data (Content-Type: appication/x-www-form-urlencoded
).
Field composition must include all mandatory fields and may include an identifier.
The response returns a created resource including the values of automatically generated fields.
POST /rest/v1/<CHAPTER>/.../<COLLECTION> HTTP/1.1
Content-Type: application/json; charset=utf-8
<resource>
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
<resource>
GET collections
Returns a list of resources from a collection with a limited set of fields.
Can be additionally filtered (filter
), sorted (order
), paginated (offset
, limit
), returned fields narrowed (mask
), output format converted using parameters (flat
).
GET /rest/v1/<CHAPTER>/.../<COLLECTION> HTTP/1.1
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
[
<resource>,
<resource>,
...
]
Name | Value type | Description |
---|---|---|
|
|
Filter elements by field values. Defined as a json structure. Examples:
Supports search terms for strings:
Supports search terms for numbers:
Supports search conditions for values of type For list fields, uses the criterion of including a list from a filter in a list from a value: For object fields, it uses the criterion that the field values specified in the filter correspond to the values of the corresponding fields of the object, allowing the use of these conditions for specifying strings, numbers, bool, lists and child objects. Alternatively, a filter format similar to the following may be used /rest/v1/model. |
|
|
Sorts resources in the specified order. Applies a sequence of fields, where each field defines a sorting direction, and applies the next field if the values match. Examples:
|
|
|
A list of resource fields to be output. By default, all fields are output. Examples:
|
|
|
Issue offset. The number from zero in the filtered ( Example:
|
|
|
The maximum number of resources to be output from a filtered ( Example:
|
|
|
Convert to flat view: values as a set of options are expanded into a first-level key view: "opts":{"a":true,"b":10} => "opts.a":true,"opts.b":10 Example:
|
|
|
When set to Example of a return value:
{ "count": 5 } Example: |
|
|
When set to Example of a return value:
{ "id": "e7adf0aa-05b7-8163-948c-3392a9660db9", "name": "Administrator", "login": "admin", "pwd": "ha_v=1;0307030703070309BFB39B099674A...", "timezone": "default", "opts":{ "allow_script_crud": true, "roles":["admin", "crud", "scripteditor", "monitor"] } } Example: |
GET resource
Returns a specific resource. The parameters can be used to narrow down the return fields (mask
) and transform the output format (flat
).
GET /rest/v1/<CHAPTER>/.../<COLLECTION>/<ENTITY_ID> HTTP/1.1
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
<resource>
Name | Value type | Description |
---|---|---|
|
|
list of fields to be output. Specifies an enumeration of fields. If the parameter is not specified, all fields will be displayed. |
|
|
planarization. |
PUT resource
Modifies the resource with the specified identifier in the collection by full replacement. The identifier cannot be replaced.
The new resource is passed as the entire request body.
Used mainly for placing files with the specified name.
PUT /rest/v1/<CHAPTER>/.../<COLLECTION>/<ENTITY_ID> HTTP/1.1
Content-Type: application/json; charset=utf-8
<resource>
POST /rest/v1/<CHAPTER>/.../<COLLECTION>/<ENTITY_ID>!put HTTP/1.1
Content-Type: application/json; charset=utf-8
<resource>
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
<resource>
PATCH resource
Modifies the resource with the specified identifier in the collection by partial overlay. The identifier cannot be replaced.
A JSON-formatted resource containing only the fields to be modified is passed as the body of the request.
A new resource with all fields is returned as the content of the response.
PATCH /rest/v1/<CHAPTER>/.../<COLLECTION>/<ENTITY_ID> HTTP/1.1
Content-Type: application/json; charset=utf-8
<resource>
POST /rest/v1/<CHAPTER>/.../<COLLECTION>/<ENTITY_ID>!patch HTTP/1.1
Content-Type: application/json; charset=utf-8
<resource>
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
<resource>
DELETE resource
Removes the resource with the specified identifier from the collection. Nothing is returned in the response content.
DELETE /rest/v1/<CHAPTER>/.../<COLLECTION>/<ENTITY_ID> HTTP/1.1
POST /rest/v1/<CHAPTER>/.../<COLLECTION>/<ENTITY_ID>!delete HTTP/1.1
HTTP/1.1 204 No Content
Specific methods
Executes the specified specific method on the specified resource. Target response in JSON format: value, resource, or collection. Parameters are also specific to each method.
<CUSTOM_METHOD> /rest/v1/<CHAPTER>/.../<COLLECTION>/<ENTITY_ID> HTTP/1.1
For example, LOOKUP /rest/v1/iam/users HTTP/1.1
.
POST /rest/v1/<CHAPTER>/.../<COLLECTION>/<ENTITY_ID>!<CUSTOM_METHOD> HTTP/1.1
For example, POST /rest/v1/iam/users!lookup HTTP/1.1
.
-
lookup
– searches for a resource in the collection by key (unique) specified parameters, returns the identifier of the matching resource. The identifier is used in the EndPoint of the resource.
Fallback inquiries
Can be used as understudies when HTTP methods cannot be performed PUT, PATCH, DELETE, HEAD.
Fallback url is built on the basis of the endpoint with the addition of “!” after the resource or collection identifier. Query method – POST.
POST /rest/v1/<CHAPTER>/.../<COLLECTION>!<FALLBACK_SUFFIX> HTTP/1.1
POST /rest/v1/<CHAPTER>/.../<COLLECTION>/<ENTITY_ID>!<FALLBACK_SUFFIX> HTTP/1.1
-
FALLBACK_SUFFIX - target method in lower case. Possible values:
-
put
– forPUT
-
patch
– forPATCH
-
delete
– forDELETE
-
head
– forHEAD
-
by analogy for any specific methods (e.g.,
SWITCH <EndPoint>
→POST <Endpoint>!switch
)
-
Content-type in queries
-
multipart/form-data
andapplication/octet-stream
for the files; -
application/json
for resources; -
application/x-www-form-urlencoded
for resources, assumes there is adata
parameter containing the target resource.
HTTP Verb | Content-Types |
---|---|
|
|
|
|
|
|
|
|
|
|
API response schema REST
Erroneous response format
{
"error_code" : <INTERNAL_CODE>,
"error_message" : <INTERNAL_MESSAGE>,
"error_details" : <INTERNAL_DETAILS>
}
-
<INTERNAL_CODE>
- internal (system) error code (int). -
<INTERNAL_MESSAGE>
- error description (str). -
<INTERNAL_DETAILS>
- optional attribute containing additional error parameters (object), e.g.{"field": "name"}
HTTP code | error_code | Description |
---|---|---|
|
Error in request parameters |
|
|
|
Authentication required |
|
|
Access to the resource/endpoint is denied |
|
|
Resource/endpoint not found |
|
|
The resource already exists |
|
|
The specified resource parameters cannot be applied |
|
|
Server error during request processing |
Content-type in response
-
application/json
to output resources, including errors, and.json
files with the appropriate content type); -
application/octet-stream
to output files in response to a download request (with the GET request parameter attachment=1); -
other mime-types to give files according to their extensions.
HTTP Verb | Content-Types |
---|---|
|
|
|
|
|
|
|
|