REST system¶
The REST system represents a REST service (i.e. a web server) serving HTTP requests from a base url using the REST vocabulary of GET, PUT, POST, PATCH, OPTIONS and HEAD.
It is used by the REST sink.
It supports the HTTP
and HTTPS
protocols. It provides session handling, connection pooling and authentication
services to sources and sinks which need to communicate with a HTTP server.
The REST system is an extension of the URL system, so all configuration properties of the URL system apply. We’ll only cover the REST system specific properties in this section.
Prototype¶
{
"_id": "id-of-system",
"name": "Name of system",
"type": "system:rest",
"url_pattern": "http://host:port/path/%s",
"verify_ssl": false,
"custom_ca_pem_chain": "-----BEGIN CERTIFICATE-----\nMIIGYTCCB[...]\n-----END CERTIFICATE-----\n",
"username": null,
"password": null,
"authentication": "basic",
"jwt_token": null,
"connect_timeout": 60,
"read_timeout": 1800,
"rate_limiting_retries": 3,
"rate_limiting_delay": 60,
"json_content_types": ["application/jsonish"]
"headers": {
"MY_HEADER": "some-value",
"MY_OTHER_HEADER": "$ENV(key-for-other-value)",
"MY_SECRET_HEADER": "$SECRET(secret-key)"
},
"operations": {
"get-operation": {
"url" : "/a/service/that/supports/get/{{ _id }}",
"method": "GET",
"next_page_link": {{ body.pagination.next }},
"next_page_termination_strategy": ["next-page-link-empty", "same-next-page-request", "same-response"]
"id_expression": {{ id }},
"updated_expression": {{ updated }},
"payload_property": "result",
"response_property": "response",
"since_property_name": "updated",
"since_property_location": "query|header|manual"
},
"delete-operation": {
"url" : "/a/service/that/supports/delete/{{ _id }}",
"method": "DELETE",
"rate_limiting_retries": 3,
"rate_limiting_delay": 60
},
"put-operation": {
"url" : "/some/service/that/supports/put",
"method": "PUT",
"headers": {
"Content-type": "application/json"
},
"payload-type": "json"
},
"post-operation": {
"url" : "/some/service/that/supports/post",
"method": "POST",
"payload-type": "form"
},
"patch-operation": {
"url" : "/some/service/that/supports/patch",
"headers": {
"Content-type": "application/xml"
},
"method": "PATCH"
}
}
}
Properties¶
Property |
Type |
Description |
Default |
Req |
---|---|---|---|---|
|
The REST system extends the URL system, so any property from the URL system can be applied. |
|||
|
Dict<String,String> |
A optional set of header values to set as defaults in the requests made using the REST system. Both keys and values must
evaluate to strings. Note that any “Authorization” header provided in this object is automatically overwritten
when using the |
||
|
Object |
An object containing the registered operations allowed for the REST service. See the Operation properties section for details.
Note that you can also define an |
||
|
Integer |
If set and the REST service returns a HTTP 429 error code, the request will be retried the number of times
indicated. The time between retries can be adjusted by setting |
||
|
Integer |
If |
1 |
|
|
Array of strings |
This property can be used to supply the REST source and transform a list of response “content-type” strings that represent valid JSON content that should be parsed as such. The content-type “application/json” is always included. |
[“application/json”] |
Operation properties¶
You can register as many named “operations” as you like with the system (even using the same type of “method”). A operation configuration looks like:
Property |
Type |
Description |
Default |
Req |
---|---|---|---|---|
|
String |
A URL or URL part. The property supports the |
Yes |
|
|
String |
A enumeration of |
Yes |
|
|
Dict<String,String> |
An optional object that contain key-value mappings for the HTTP request header. Entries in this dictionary
will override any default |
||
|
Objects |
An optional object that contain key-value mappings for any HTTP parameters. The property supports the
|
||
|
Enum<String> |
A enumeration of “text”, “json”, “json-transit”, “form” and “multipart-form”, that denotes how to treat the
|
|
|
|
Object |
The properties mapping used as default values for the emitted entities. Note that if both are present the properties in the emitted entity takes precedence. Also note that this property can be defined in the REST source, REST transform and REST sink configuration as well. The configuration in pipes will take precedence if both are defined. |
||
|
Object, string or array |
The value to use as payload for the operation. Note that this property can be defined in the REST source,
REST transform and REST sink configuration as well, but only the
|
||
|
String |
The name of the property to put the response in when emitting entities. Note that this property can be defined in the REST source and REST transform configuration as well. The configuration in pipes will take precedence if both are defined. |
||
|
String |
The name of the property to put the response headers in when emitting entities. Note that this property can be defined in the REST source and REST transform configuration as well. The configuration in pipes will take precedence if both are defined. |
||
|
String |
The name of the property to put the response status code in when emitting entities. Note that this property can be defined in the REST source and REST transform configuration as well. The configuration in pipes will take precedence if both are defined. |
||
|
String |
The JSON response sub-property to use as the source of the emitted entities. Note that this property can be defined in the REST source and REST transform configuration as well. It will be ignored by the REST sink. The configuration in pipes will take precedence if both are defined. |
||
|
String |
The property supports the |
||
|
Enum<String> or array of Enum<String> |
Enumeration of |
|
|
|
Integer |
An integer indicating the number of entities contained in a paged response. This property must be set if the
|
||
|
String |
An expression in the form of single values or value ranges of HTTP status codes that will be allowed to be passed
through by the transform. The values are either comma separated integer values or a range of values with a hyphen separator
(i.e. a single Note This operation property can only be used with the REST transform. Warning If you allow other status codes than the default, make sure that these are dealt with downstream. |
|
|
|
String |
An expression in the form of single values or value ranges of HTTP status codes that will be ignored by the
transform. HTTP responses with status codes matching this list will result in the response being omitted from
the result. The values are either comma separated integer values or a range of values with a hyphen separator
(i.e. a single Note This operation property can only be used with the REST transform. Warning Any response with status codes listed here will be discarded with no traces to be found, making it next to impossible to audit the pipe. |
||
|
String |
The property supports the |
||
|
String |
The property supports the |
||
|
String |
The property supports the |
||
|
String |
The name of the property to relay continuation information. This is only relevant if |
|
|
|
String |
A enumeration of |
|
|
|
Integer |
If set and the REST service returns a HTTP 429 error code, the request will be retried the number of times
indicated. The time between retries can be adjusted by setting |
||
|
Integer |
If |
1 |
Notes on Jinja templates¶
(experimental)
The payload
, headers
and params
operation configuration properties are objects where the properties can be
templated using Jinja (both the key and the values) with various dynamically bound parameters. This makes it possible to construct
these request parameters dynamically. You can also control whether a particular property is included in the final
object by injecting a special marker constant "sesam:markskip"
using conditional logic. If this marker is present in the
rendered template, then the property is omitted from its parent object. Note that you can use this marker in both keys and values.
An example:
{
"_id": "our-rest-service",
"name": "Our REST service",
"url_pattern": "http://our.domain.com/api/%s",
"type": "system:rest",
"operations": {
"post-operation": {
"url" : "{{ properties.url }}/some-path",
"method": "POST",
"payload-type": "json",
"payload": {
"key": "value",
"conditional_key": "{% if entity.conditional_property is defined %}{{ entity.conditional_property }}{% else %}sesam:markskip{% endif %}",
"some_other_key{% if entity.other_conditional_property is not defined %}sesam:markskip{% endif %}": "other_value"
}
}
..
(experimental)
You can use the special marker "sesam:markjson"
to construct JSON objects, lists or single values from a templated string in the payload
, headers
and params
operation configuration properties. It can be used to cast Jinja templated strings to JSON data types or construct objects or lists with conditional Jinja logic.
An example:
{
"_id": "our-rest-service",
"name": "Our REST service",
"url_pattern": "http://our.domain.com/api/%s",
"type": "system:rest",
"operations": {
"post-operation": {
"url" : "{{ properties.url }}/some-path",
"method": "POST",
"payload-type": "json",
"payload": {
"key": "{{ properties.integer_property }}system:markjson",
"some_other_key": "[{{ properties.arg1, \"literal value \"}}]sesam:markjson"
}
}
..
Result payload object:
..
"payload": {
"key": 10,
"some_other_key": [1.2, \"literal value \"]
}
..
Example configuration¶
{
"_id": "our-rest-service",
"name": "Our REST service",
"url_pattern": "http://our.domain.com/api/%s",
"type": "system:rest",
"operations": {
"get-men": {
"url" : "men/{{ properties.collection_name }}/men/{{ since }}",
"method": "GET"
},
"get-man": {
"url" : "men/{{ properties.collection_name }}/{{ _id }}",
"method": "GET"
},
"get-woman": {
"url" : "women/{{ properties.collection_name }}/{{ _id }}",
"method": "GET"
},
"delete-man": {
"url" : "men/{{ properties.collection_name }}/{{ _id }}",
"method": "DELETE"
},
"delete-woman": {
"url" : "women/{{ properties.collection_name }}/{{ _id }}",
"method": "DELETE"
},
"update-man": {
"url" : "men/{{ properties.collection_name }}/",
"method": "POST",
"headers": {
"Content-type": "application/xml"
}
},
"update-woman": {
"url" : "women/{{ properties.collection_name }}/",
"method": "POST",
"headers": {
"Content-type": "application/json"
},
"payload-type": "json"
},
"form-operation": {
"url" : "men/{{ properties.collection_name }}/submit-form",
"method": "POST",
"payload-type": "form"
},
"multipart-form-operation": {
"url" : "men/{{ properties.collection_name }}/submit-multipart-form",
"method": "POST",
"payload-type": "multipart-form"
}
}
}