|
| 1 | +# Event Target for HTTP |
| 2 | + |
| 3 | +This event target receives [CloudEvents][ce] and turns them into HTTP requests that consume external services. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +The HTTP event target sends requests to arbitrary URLs and wraps responses in CloudEvents back to the caller. HTTP endpoints that are unauthenticated, use basic authentication or use custom header values for authentication, can be integrated using this target. |
| 8 | + |
| 9 | +Responses from external HTTP endpoints are converted into CloudEvents and sent as a reply to the TriggerMesh Broker/Channel. It is important that the HTTP target filters received events and cares about response event type and event source to avoid loops where those responses might end up being processed by the HTTP Target. |
| 10 | + |
| 11 | +Requests from this HTTP target will verify TLS certificates from the remote server if present. If the CA certificate at the server is self-signed, the public certificate needs to be added to the configuration, or alternatively mark the `Skip Verify` option. |
| 12 | + |
| 13 | +If the remote endpoint requires basic authentication, the password needs to be created as a secret. |
| 14 | + |
| 15 | +## Create the HTTP Target Integration |
| 16 | + |
| 17 | +Create an instance of the HTTP Target at TriggerMesh as part of a Bridge. |
| 18 | + |
| 19 | +- `Name` is an internal identifier for the target. |
| 20 | +- `Response event type` must be set and will identify the type for responses from the remote endpoint. |
| 21 | +- `EventSource` will identify the origin for all responses. When not informed source will be automatically set to a generated name that includes the HTTP Target component name. |
| 22 | +- `Endpoint` full URL for the remote service, including path and query string if any. |
| 23 | +- `Method` to use when executing requests against the remote endpoint. |
| 24 | +- `CA Certificate` CA certificate configured for TLS connection. |
| 25 | +- `Skip Verify` skips remote server TLS certificate verification. |
| 26 | +- `Username` when using basic authentication. |
| 27 | +- `Password` when using basic authentication needs to reference the aforementioned password secret. |
| 28 | +- `Headers` is a set of key/value pairs that will be set withing the HTTP request. |
| 29 | + |
| 30 | +Save the target, fill the rest of the bridge components, and press `Submit Bridge`. |
| 31 | + |
| 32 | +## Trigger Configuration |
| 33 | + |
| 34 | +Responses from the remote endpoint will generate new CloudEvents that will be returned to TriggerMesh. Those response events should not be re-processed by the HTTP Target. |
| 35 | + |
| 36 | +It is important that the Trigger that subscribes the HTTP Target to the Broker configure the appropriate filters to avoid these loops. |
| 37 | + |
| 38 | +As an example: |
| 39 | + |
| 40 | +- We configure an HTTP Target to integrate with WorkDay. |
| 41 | +- HTTP Target is interested in events whose type is `calendar.pto.request`. |
| 42 | +- The response from workday will generate a CloudEvent type `workday.pto.response` and source `workday.instance1` |
| 43 | + |
| 44 | +Trigger should be configured to avoid feeding these responses into the HTTP Target. A filter key `type` and value `calendar.pto.request` would provide such protection. |
| 45 | + |
| 46 | +## Events Types |
| 47 | + |
| 48 | +The HTTP Target expects a CloudEvent request that complements the Target configured values. |
| 49 | + |
| 50 | +There is no requirement regarding the type header value. Any CloudEvent containing the expected data is valid to process. Data needs to be a JSON structure that might contain these optional fields: |
| 51 | + |
| 52 | + |
| 53 | +| Field | Description | Example | |
| 54 | +|--- |--- |--- | |
| 55 | +| query_string | Key/value pairs formatted as query string | `name=jane&lastname=doe` | |
| 56 | +| path_suffix | Will be appended to the target's path | `apparel/tshirts` | |
| 57 | +| body | String to be set as the request body | `{\"size\":\"L\",\"color\":\"beige\"}` | |
| 58 | + |
| 59 | +CloudEvent data examples: |
| 60 | + |
| 61 | +```json |
| 62 | +{"path_suffix":"world/italy/cities", "query_string":"top=10&format=csv"} |
| 63 | +``` |
| 64 | + |
| 65 | +If body is a JSON structure, it will need to be _stringified_ |
| 66 | + |
| 67 | +```json |
| 68 | +{"body": "{\"records\":[{\"value\":{\"this\":{\"is\": \"sparta\"}}}]}"} |
| 69 | +``` |
| 70 | + |
| 71 | +[ce]: https://cloudevents.io |
0 commit comments