|
1 | 1 | ---
|
2 |
| -title: "HTTP Target" |
| 2 | +title: "HTTP" |
3 | 3 | description: "Send data over HTTP."
|
4 | 4 | ---
|
5 | 5 |
|
| 6 | +:::note |
| 7 | +Version 3.0.0 makes breaking changes to the http target. Details on migrating can be found [in the migration guide](/docs/destinations/forwarding-events/snowbridge/3-X-X-upgrade-guide/index.md) |
| 8 | +::: |
| 9 | + |
6 | 10 | ## Basic Authentication
|
7 | 11 |
|
8 |
| -Where basicauth is used, it may be configured using the `basic_auth_username` and `basic_auth_password` options. Where an authorisation header is used, it may be set via the `headers` option. |
| 12 | +Where basicauth is used, it may be configured using the `basic_auth_username` and `basic_auth_password` options. Where an authorization header is used, it may be set via the `headers` option. |
9 | 13 |
|
10 |
| -we recommend using environment variables for sensitive values - which can be done via HCL's native `env.MY_ENV_VAR` format (as seen below). |
| 14 | +We recommend using environment variables for sensitive values - which can be done via HCL's native `env.MY_ENV_VAR` format (as seen below). |
11 | 15 |
|
12 | 16 | TLS may be configured by providing the `key_file`, `cert_file` and `ca_file` options with paths to the relevant TLS files.
|
13 | 17 |
|
14 | 18 | ## OAuth2
|
15 | 19 |
|
16 |
| -Snowbridge supports sending authorized requests to OAuth2 - compliant HTTP targets. This can be enabled in by setting `oauth2_client_id `, `oauth2_client_secret`, `oauth2_refresh_token` (these 3 are long-lived credentials used to generate short-lived bearer access tokens) and `oauth2_token_url`(which is the URL of authorization server providing access tokens). |
| 20 | +Snowbridge supports sending authorized requests to OAuth2-compliant HTTP targets. This can be enabled by setting `oauth2_client_id`, `oauth2_client_secret`, `oauth2_refresh_token` (these three are long-lived credentials used to generate short-lived bearer access tokens), and `oauth2_token_url` (which is the URL of the authorization server providing access tokens). |
17 | 21 |
|
18 | 22 | Like in the case of basic authentication, we recommend using environment variables for sensitive values.
|
19 | 23 |
|
| 24 | +## Dynamic headers |
| 25 | + |
| 26 | +:::note |
| 27 | +This feature was added in version 2.3.0 |
| 28 | +::: |
| 29 | + |
| 30 | +When enabled, this feature attaches a header to the data according to what your transformation provides in the `HTTPHeaders` field of `engineProtocol`. Data is batched independently per each dynamic header value before requests are sent. |
| 31 | + |
| 32 | +## Request templating |
| 33 | + |
| 34 | +:::note |
| 35 | +This feature was added in version 3.0.0 |
| 36 | +::: |
| 37 | + |
| 38 | +This feature allows you to provide a [Golang text template](https://pkg.go.dev/text/template) to construct a request body from a batch of data. This feature should be useful in constructing requests to send to an API, for example. |
| 39 | + |
| 40 | +Input data must be valid JSON, any message that fails to be marshaled to JSON will be treated as invalid and sent to the failure target. Equally, if an attempt to template a batch of data results in an error, then all messages in the batch will be considered invalid and sent to the failure target. |
| 41 | + |
| 42 | +Where the dynamic headers feature is enabled, data is split into batches according to the provided header value, and the templater will operate on each batch separately. |
| 43 | + |
| 44 | +### Helper functions |
| 45 | + |
| 46 | +In addition to all base functions available in the Go text/template package, the following custom functions are available for convenience: |
| 47 | + |
| 48 | +`prettyPrint` - Because the input to the templater is a Go data structure, simply providing a reference to an object field won't output it as JSON. `prettyPrint` converts the data to prettified JSON. Use it wherever you expect a JSON object in the output. This is compatible with any data type, but it shouldn't be necessary if the data is not an object. |
| 49 | + |
| 50 | +`env` - Allows you to set and refer to an env var in your template. Use it when your request body must contain sensitive data, for example an API key. |
| 51 | + |
| 52 | +### Template example |
| 53 | + |
| 54 | +The following example provides an API key via environment variable, and iterates the batch to provide JSON-formatted data one by one into a new key, inserting a comma before all but the first event. |
| 55 | + |
| 56 | +```hcl reference |
| 57 | +https://github.com/snowplow/snowbridge/blob/master/assets/docs/configuration/targets/http-template-full-example.file |
| 58 | +``` |
| 59 | + |
| 60 | +## Response rules (beta) |
| 61 | + |
| 62 | +:::note |
| 63 | +This feature was added in version 3.0.0 |
| 64 | + |
| 65 | +This feature is in beta status because we may make breaking changes in future versions. |
| 66 | +::: |
| 67 | + |
| 68 | +Response rules allow you to configure how the app deals with failures in sending the data. You can configure a response code and an optional string match on the response body to determine how a failure response is handled. Response codes between 200 and 299 are considered successful, and are not handled by this feature. |
| 69 | + |
| 70 | +There are three categories of failure: |
| 71 | + |
| 72 | +`invalid` means that the data is considered incompatible with the target for some reason. For example, you may have defined a mapping for a given API, but the event happens to have null data for a required field. In this instance, retrying the data won't fix the issue, so you would configure an invalid response rule, identifying which responses indicate this scenario. |
| 73 | + |
| 74 | +Data that matches an invalid response rule is sent to the failure target. |
| 75 | + |
| 76 | +`setup` means that this error is not retryable, but is something which can only be resolved by a change in configuration or a change to the target. An example of this is an authentication failure - retrying will fix the issue, the resolution is to grant the appropriate permissions, or provide the correct API key. |
| 77 | + |
| 78 | +Data that matches a setup response rule is handled by a retry as determined in the `setup` configuration block of [retry configuration](/docs/destinations/forwarding-events/snowbridge/configuration/retries/index.md). |
| 79 | + |
| 80 | +`transient` errors are everything else - we assume that the issue is temporary and retrying will resolve the problem. An example of this is being throttled by an API because too much data is being sent at once. There is no explicit configuration for transient - rather, anything that is not configured as one of the other types is considered transient. |
| 81 | + |
20 | 82 | ## Configuration options
|
21 | 83 |
|
22 | 84 | Here is an example of the minimum required configuration:
|
|
0 commit comments