HTTP Request
Description
Http request pipe performs an http request.
Peculiarities:
Depending on prams.content_type:
- form, form-data – data is expected in params.form;
- xml, json – data is expected in $in.body (must be a byte array).
Structure
| Field | Type of value | Example | Required | Description |
|---|---|---|---|---|
| id | number | 10 | yes | Pipe's ID |
| type | string | "http_request" | yes | Type of a pipe |
| params | HttpParamsObject | yes | Type-specific parameters | |
| outs | OutsObject | no | Pipe's outputs |
| HttpParamsObject | |||||
|---|---|---|---|---|---|
| Fiеld | Type | Example | Required | Default | Description |
| content_type | string | "json" | no | "form" | Possible values:
|
| method | stringп | "POST" | no | "GET" | Possible values:
|
| auth_type | string | "basic" | no | "basic" | Possible values:
Will be enabled if specified auth_username. Requires auth_username and auth_password
. Sets a title
|
| auth_username | stringа | "root" | no | "" | Login for basic authorization |
| auth_password | string | "1234" | no | "" | Password for basic authorization |
| url | string | "http://exmaple.com/send" | no | "" | URL |
| timeout | тгьиук | 20 | тщ | PIPE_HTTP_TIMEOUT in the configuration file | Timeout in seconds for http request. |
| success_codes | array of numbers | [200, 201] | no | [200, 201, 202, 203, 204, 205, 206, 207, 208] | An array of http codes, if one of them is present, the event will be sent to outs.success exit. |
| pool_size | number | 10 | no | PIPE_HTTP_MAX_CONN in the configuration file | Limiting the connection pool to one host within a channel. Increasing pool_size may not bring the desired speed increase without increasing the PIPE_WORKER_SIZE parameter in the configuration file |
| limit | LimitObject |
| no | - | Limiting the request rate. tip The default request rate depends on the pipeline configuration, but is approximately 200 - 300 requests per second. |
| headers | object |
| no | - | Request headers |
| form | object |
| no | - | A key:value object that specifies the form for the content_type form and form-data |
| LimitObject | |||||
|---|---|---|---|---|---|
| Fiеld | Type | Example | Required | Default | Description |
| period_sec | number | 1 | yes | - | Range in seconds |
| count_requests | number | 2 | yes | - | The allowed number of requests in the specified time range for the selected key. The limit is valid within the limits of key in the channel |
| key | string | "$resource.token" | no | random uuid | Constraint ID. Can be a constant or a template. Needed to set one restriction on several http_request pipes |
Errors
- Errors in field template processing.
$in.body not found (missing pack pipe).
$in.body not a byte array.
params.content_type not valid.
params.method not valid.
- http request error.
Examples
- Example request with form.
{
"id": 3,
"type": "http_request",
"params": {
"method": "POST",
"timeout": 10,
"content_type": "FORM",
"form": {
"login": "$sender.login",
"password": "$sender.password",
"externalUserCode": "$sender.login"
},
"url": "https://example.com/api/v1.0/sessions",
"success_codes": [200, 202]
},
"outs": {
"success": 6,
"error": 7
}
}
- Example request with JSON. It is assumed that in the chain before the pipe there is a pack pipe that generates JSON.
{
"id": 2,
"type": "http_request",
"params": {
"method": "POST",
"timeout": 10,
"content_type": "JSON",
"headers": {
"Authorization": "$in.ow_tp $in.ow_token"
},
"url": "https://example.com/api/v1/api/campaign/start",
"success_codes": [200, 202]
},
"outs": {
"success": 9,
"error": 10
}
}