Skip to main content

Protocols

Protocol Directive

protocol = graphql

If protocol is omitted, the request is ordinary HTTP.

Hen currently supports:

  • HTTP by default
  • protocol = graphql
  • protocol = sse
  • protocol = ws

GraphQL

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

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

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.