REST sink¶
This is a data sink that can communicate with a REST service using HTTP requests.
Note that the shape of the entities piped to this sink must conform to certain criteria, see the notes later in the section.
The pipe’s batch_size defaults to 1 when this sink-type is being used.
Prototype¶
{
"type": "rest",
"system" : "rest-system",
"operation": "the-default-operation",
"rate_limiting_retries": 3,
"rate_limiting_delay": 60,
"properties": {
"the-default": "properties"
},
"payload": {
"the-default": "payload"
}
}
Properties¶
Property |
Type |
Description |
Default |
Req |
---|---|---|---|---|
|
String |
The id of the REST system to use. |
Yes |
|
|
String |
The default id of the operation to use if not present in the entity. |
||
|
Object |
A mapping to use for properties not available in the entity. Note that if the |
||
|
Object, string or array |
The value to use as payload for the operation if not present in the entity. Note that this property can be
defined in the specified |
||
|
Boolean or Object |
This can be set to |
|
No |
|
Boolean |
If the |
|
No |
|
Integer |
If the |
100 |
No |
|
Boolean |
If the |
|
No |
|
Integer |
If the |
100 |
No |
|
Integer |
If the |
600 |
No |
Expected entity shape¶
The entities must be transformed into a particular form before being piped to the RESTsink. The general form expected is:
{
"_id": "1",
"properties": {
"foo": "bar",
"zoo": 1,
"baz": [1,2,3]
},
"operation": "some-named-operation",
"payload": "<some>string-value</some>"
}
Property |
Type |
Description |
Default |
Req |
---|---|---|---|---|
|
Object |
Any non-payload properties you need should go into the toplevel child entity |
||
|
String |
The contents of this property must refer to one of the named |
||
|
Object |
An object containing the registered operations allowed for the |
||
|
String or Object |
The payload for the operation specified. It can be a string or an object. You can also omit it, in which case the empty string will be used instead (for example for “DELETE” methods). All string payloads will be encoded as UTF-8. |
||
|
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 |
Example entities:
String as payload:
{
"_id": "1",
"properties": {
"foo": "bar",
"zoo": 1,
"baz": [1,2,3]
},
"operation": "some-named-operation",
"payload": "<some>string-value</some>"
}
Object as payload (set operation payload-type
to “json”, “json-transit” or “form” in the REST system the sink uses):
{
"_id": "2",
"properties": {
"foo": "bar",
"zoo": 1,
"baz": [1,2,3]
},
"operation": "some-other-operation",
"payload": {
"payload": "property",
"child": {
"foo": "bar"
}
}
}
If the payload-type
is “form” or “multipart-form” the request will encode the contents as a HTML form submission
with either a application/x-www-form-urlencoded
or multipart/form
Content-Type, respectively.
The form variables and corresponding values should be given as a dictionary of variable-name/variable-value pairs as
the contents of payload
:
{
"_id": "3",
"operation": "form-or-multi-part-form-operation",
"payload": {
"form-variable": "form-value",
"other-form-variable": "other-form-value"
}
}
Example configuration¶
See the REST system example section for how to configure the operations we refer to in these examples:
{
"type" : "pipe",
"sink" : {
"type" : "rest",
"system" : "our-rest-service",
"operation": "update-woman",
"properties": {
"sex": "F"
},
"payload": {
"id": "unknown",
"collection_name": "study-group-1"
}
}
}
Example input entities:
[
{
"_id": "john",
"operation": "update-man",
"properties": {
"id": "john",
"age": 21,
"sex": "M"
},
"payload": "<man id=\"john\">john</man>"
},
{
"_id": "mary",
"properties": {
"id": "mary",
"age": 23,
"collection_name": "study-group-2"
},
"payload": {
"id": "mary",
"age": 23
}
},
{
"_id": "bob",
"operation": "delete-man",
"properties": {
"collection_name": "study-group-1"
}
}
]