http

Performs an HTTP request using a message batch as the request body, and replaces the original message parts with the body of the response.

# Common config fields, showing default values
http:
parallel: false
url: http://localhost:4195/post
verb: POST
headers:
Content-Type: application/octet-stream
rate_limit: ""
timeout: 5s

If a processed message batch contains more than one message they will be sent in a single request as a multipart message. Alternatively, message batches can be sent in parallel by setting the field parallel to true.

The rate_limit field can be used to specify a rate limit resource to cap the rate of requests across all parallel components service wide.

The URL and header values of this type can be dynamically set using function interpolations described here.

In order to map or encode the payload to a specific request body, and map the response back into the original payload instead of replacing it entirely, you can use the branch processor.

Response Codes

Benthos considers any response code between 200 and 299 inclusive to indicate a successful response, you can add more success status codes with the field successful_on.

When a request returns a response code within the backoff_on field it will be retried after increasing intervals.

When a request returns a response code within the drop_on field it will not be reattempted and is immediately considered a failed request.

Adding Metadata

If the request returns an error response code this processor sets a metadata field http_status_code on the resulting message.

If the field copy_response_headers is set to true then any headers in the response will also be set in the resulting message as metadata.

Error Handling

When all retry attempts for a message are exhausted the processor cancels the attempt. These failed messages will continue through the pipeline unchanged, but can be dropped or placed in a dead letter queue according to your config, you can read about these patterns here.

Examples

This example uses a branch processor to strip the request message into an empty body, grab an HTTP payload, and place the result back into the original message at the path repo.status:

pipeline:
processors:
- branch:
request_map: 'root = ""'
processors:
- http:
url: https://hub.docker.com/v2/repositories/jeffail/benthos
verb: GET
result_map: 'root.repo.status = this'

Fields

parallel

When processing batched messages, whether to send messages of the batch in parallel, otherwise they are sent within a single request.

Type: bool
Default: false

url

The URL to connect to. This field supports interpolation functions.

Type: string
Default: "http://localhost:4195/post"

verb

A verb to connect with

Type: string
Default: "POST"

# Examples
verb: POST
verb: GET
verb: DELETE

headers

A map of headers to add to the request. This field supports interpolation functions.

Type: object
Default: {"Content-Type":"application/octet-stream"}

# Examples
headers:
Content-Type: application/octet-stream

oauth

Allows you to specify open authentication via OAuth version 1.

Type: object

oauth.enabled

Whether to use OAuth version 1 in requests.

Type: bool
Default: false

oauth.consumer_key

A value used to identify the client to the service provider.

Type: string
Default: ""

oauth.consumer_secret

A secret used to establish ownership of the consumer key.

Type: string
Default: ""

oauth.access_token

A value used to gain access to the protected resources on behalf of the user.

Type: string
Default: ""

oauth.access_token_secret

A secret provided in order to establish ownership of a given access token.

Type: string
Default: ""

oauth.request_url

The URL of the OAuth provider.

Type: string
Default: ""

oauth2

Allows you to specify open authentication via OAuth version 2 using the client credentials token flow.

Type: object

oauth2.enabled

Whether to use OAuth version 2 in requests.

Type: bool
Default: false

oauth2.client_key

A value used to identify the client to the token provider.

Type: string
Default: ""

oauth2.client_secret

A secret used to establish ownership of the client key.

Type: string
Default: ""

oauth2.token_url

The URL of the token provider.

Type: string
Default: ""

basic_auth

Allows you to specify basic authentication.

Type: object

basic_auth.enabled

Whether to use basic authentication in requests.

Type: bool
Default: false

basic_auth.username

A username to authenticate as.

Type: string
Default: ""

basic_auth.password

A password to authenticate with.

Type: string
Default: ""

tls

Custom TLS settings can be used to override system defaults.

Type: object

tls.enabled

Whether custom TLS settings are enabled.

Type: bool
Default: false

tls.skip_cert_verify

Whether to skip server side certificate verification.

Type: bool
Default: false

tls.root_cas_file

The path of a root certificate authority file to use.

Type: string
Default: ""

tls.client_certs

A list of client certificates to use. For each certificate either the fields cert and key, or cert_file and key_file should be specified, but not both.

Type: array

# Examples
client_certs:
- cert: foo
key: bar
client_certs:
- cert_file: ./example.pem
key_file: ./example.key

tls.client_certs[].cert

A plain text certificate to use.

Type: string
Default: ""

tls.client_certs[].key

A plain text certificate key to use.

Type: string
Default: ""

tls.client_certs[].cert_file

The path to a certificate to use.

Type: string
Default: ""

tls.client_certs[].key_file

The path of a certificate key to use.

Type: string
Default: ""

copy_response_headers

Sets whether to copy the headers from the response to the resulting payload.

Type: bool
Default: false

rate_limit

An optional rate limit to throttle requests by.

Type: string
Default: ""

timeout

A static timeout to apply to requests.

Type: string
Default: "5s"

retry_period

The base period to wait between failed requests.

Type: string
Default: "1s"

max_retry_backoff

The maximum period to wait between failed requests.

Type: string
Default: "300s"

retries

The maximum number of retry attempts to make.

Type: number
Default: 3

backoff_on

A list of status codes whereby retries should be attempted but the period between them should be increased gradually.

Type: array
Default: [429]

drop_on

A list of status codes whereby the attempt should be considered failed but retries should not be attempted.

Type: array
Default: []

successful_on

A list of status codes whereby the attempt should be considered successful (allows you to configure non-2XX codes).

Type: array
Default: []

proxy_url

An optional HTTP proxy URL.

Type: string
Default: ""