# Show webhooks

Give a service an address on streamview, and see each webhook that it sends as an event on the timeline.

Source: https://www.eventcatalog.dev/tools/streamview/docs/how-to/show-webhooks

A webhook is an HTTP request that a service sends to you when something occurs.
streamview makes one event from each webhook. It does not need CloudEvents, an adapter, or Node.js.

streamview does not check the signature of a webhook. It shows each request that arrives.

## Start streamview

Run this command:

```
streamview webhooks
```

The browser opens. The page is empty until the first webhook arrives.

## Send a test webhook

1. Run this command in a different terminal:

```
curl -X POST http://localhost:4747/webhooks/shop \
  -H 'Content-Type: application/json' \
  -d '{"event":"order.paid","orderId":"ord_1","total":42}'
```

2. Read the answer:

```
{"accepted":true,"type":"shop.order.paid","id":"wh-1a23ad82ed3-0"}
```

3. Look at the page. After approximately 2 seconds, the event shows in the lane `shop.order.paid`.

## Give each service an address

The address of a webhook is `/webhooks/NAME`. You select the name.
Use one name for each service, for example `/webhooks/stripe` and `/webhooks/github`.

The name can have letters, digits, and the characters `.`, `_`, and `-`.
The name is the start of the event type, and it is the `channel` of the event.

streamview finds the kind of the event in the headers or in the body of the webhook.
Each kind gets a lane of its own, for example `stripe.payment_intent.succeeded` and `stripe.charge.refunded`.
See [Events from webhooks](https://www.eventcatalog.dev/tools/streamview/docs/reference/event-format#events-from-webhooks) for the places where streamview looks.

## Receive webhooks from a service on the internet

A service on the internet cannot connect to `localhost`. A tunnel gives your computer a public address.
These steps use `cloudflared`, the tunnel program of Cloudflare. Other tunnel programs work the same way.

:::caution
The public address shows the streamview page also. Each person who has the address can read your events and send events.
Stop the tunnel when you do not use it.
:::

1. Start streamview: `streamview webhooks`.
2. Run this command in a different terminal:

```
cloudflared tunnel --url http://localhost:4747
```

3. Find the address in the output. It ends with `trycloudflare.com`.
4. In the settings of the service, give this webhook address: the public address, then `/webhooks/`, then your name.

For example: `https://example-words.trycloudflare.com/webhooks/stripe`.

The public address can need some seconds before it works.

If the server runs on a computer that the service can connect to, you do not need a tunnel.
Start streamview with `--host 0.0.0.0`. See [Share a view](https://www.eventcatalog.dev/tools/streamview/docs/how-to/share-a-view).

## Give a webhook an icon

Add `icon` to the address that you give to the service. An emoji is the simplest icon:

```
http://localhost:4747/webhooks/stripe?icon=💳
```

The value can also be the address of an image. See [The icon of a lane](https://www.eventcatalog.dev/tools/streamview/docs/reference/event-format#the-icon-of-a-lane).

## Set the type yourself

If a service does not say what kind of event it sends, the type is only the name.
To give the type, add `?type=` to the address:

```
https://example-words.trycloudflare.com/webhooks/builds?type=build.finished
```

All webhooks to this address then have the type `build.finished`.

## Connect the webhooks of one order

streamview connects events that have the same correlation ID. Tell it which field of the body has the ID.

For all addresses, start streamview with `--correlation-field`:

```
streamview webhooks --correlation-field orderId
```

For one address, add `?correlation-field=` to the address:

```
http://localhost:4747/webhooks/stripe?correlation-field=data.object.metadata.order_id
```

- Use a period to go into an object, as in `data.object.metadata.order_id`.
- Use a comma between two or more fields. streamview uses the first field that the body has.

When two services send the same ID, the trace shows their webhooks together.

## Show webhooks and a broker together

Each streamview server that stores events accepts webhooks: `kafka`, `nats`, `rabbitmq`, `serve`, and `demo`.
Send the webhooks to the same port. Their lanes show below the lanes of the broker.

## Related

- [Events from webhooks](https://www.eventcatalog.dev/tools/streamview/docs/reference/event-format#events-from-webhooks)
- [HTTP endpoints](https://www.eventcatalog.dev/tools/streamview/docs/reference/http-endpoints)
- [Follow one order](https://www.eventcatalog.dev/tools/streamview/docs/how-to/follow-one-order)
