hen 0.20.2

Run protocol-aware API request collections from the command line or through MCP.
Documentation
---
sidebar_position: 7
title: Protocols
description: Extend the Hen authoring model across GraphQL, SSE, and WebSocket flows.
---

## Protocol Directive

```hen
protocol = graphql
```

If `protocol` is omitted, the request is ordinary HTTP.

Hen currently supports:

- HTTP by default
- `protocol = graphql`
- `protocol = sse`
- `protocol = ws`

## GraphQL

```hen
protocol = graphql
POST https://example.com/graphql
operation = GetUser
variables = {"id":"123"}

~~~graphql
query GetUser($id: ID!) {
  user(id: $id) {
    id
  }
}
~~~
```

- GraphQL requests currently require `POST`
- `graphql.data...` and `graphql.errors...` alias JSON body paths
- callback environments receive `GRAPHQL_DOCUMENT`, `GRAPHQL_OPERATION`, and `GRAPHQL_VARIABLES`

## SSE

```hen
protocol = sse
session = prices
receive
within = 5s
```

- SSE opening requests currently require `GET`
- `receive` consumes the next queued event for the named session
- `sse.event` and `sse.id` are available for captures and assertions
- when the event payload is valid JSON, ordinary `body...` paths work for assertions and captures
- if the opening step omits `Accept`, Hen sends `Accept: text/event-stream` automatically

## WebSocket

```hen
protocol = ws
session = chat
within = 2s
~~~json
{"type":"hello"}
~~~
```

- WebSocket opening requests currently require `GET`
- a body block implies a send step
- body plus `within` turns a step into an exchange step
- `ws.kind` exposes the observed frame type

For `protocol = ws`, plain `~~~` or `~~~text` sends text, while `~~~json` or
`~~~application/json` sends JSON.