Webhook source (HTTP)
This source exposes an HTTP endpoint, meaning it acts as an HTTP server. It can be used as a target endpoint for 3rd-party webhooks from any SaaS app that supports webhooks, or can be used as a generic way to ingest events to TriggerMesh via HTTP. The Webhook source creates an event for each request received.
Compared to the CloudEventsSource, the Webhook source can accept arbitrary data (e.g. any JSON) and does not require the request to conform to the CloudEvents specification.
With tmctl
:
On Kubernetes:
apiVersion: sources.triggermesh.io/v1alpha1
kind: WebhookSource
metadata:
name: sample
spec:
eventType: com.example.mysample.event
eventSource: instance-abc123
eventExtensionAttributes:
from:
- path
- queries
basicAuthUsername: customuser
basicAuthPassword:
value: abc123secret
sink:
ref:
apiVersion: eventing.knative.dev/v1
kind: Broker
name: default
Parameters
- Name: all TriggerMesh components need a unique name per namespace.
- Broker: request converted into CloudEvents will be sent to this location.
- EventType: string that identifies the purpose for all messages produced from this source.
- EventSource: string that identifies the origin for all messages produced from this source.
- Basic Auth Username: (optional) HTTP basic authentication username.
- Basic Auth Password (optional) points to a secret that contains the HTTP basic authentication password.
Events produced have the following attributes:
- type: defined by the user in the WebhookSource configuration, e.g.
shopify.user.new
- source: defined by the user in the WebhookSource configuration, e.g.
cool-tshirts
- Schema of the
data
attribute: depends on what the client sends to the Webhook datacontenttype
is set to theContent-Type
received at the incoming request
Cloud Event data example (same as received body):
See the Kubernetes object reference for more details.
Guide: use tmctl
to create a Webhook source
Create an HTTP endpoint
HTTP is one of the easiest ways to send events to the Broker from whichever HTTP client you prefer (Postman, Curl, API Tester...). To do this, let's create a Webhook Source:
We're declaring that events of type contact.created
will be sent to this endpoint. This event type will be part of the event metadata as it flows through TriggerMesh, and can be used later on for routing.
Obtain the URL
Find the Webhook Source URL:
The output should look something like this:
tmctl % tmctl describe
Broker Status
foo online(http://localhost:59882)
Source Kind EventTypes Status
foo-webhooksource webhooksource contact.created online(http://localhost:59936)
As you can see, tmctl describe
displays useful info about your current configuration. It lists all the sources, targets, and other components you've defined, and their properties.
Copy the webhooksource URL, in this case http://localhost:59936
(this will vary depending on your environment). Do not confuse this with the Broker's URL.
Send an event over HTTP
We'll use curl here. Remember to replace the endpoint URL with yours.
The event should show up in tmctl watch
: