hen 0.20.2

Run protocol-aware API request collections from the command line or through MCP.
Documentation
---
sidebar_position: 3
title: Syntax Cheatsheet
description: Learn the most common Hen syntax patterns on one page.
---

Use this page as the fast authoring reference before you move into the full
[Language Reference](../reference/index.md).

## Collection shape

```hen
name = Example Collection

$ API_ORIGIN = https://api.example.com
$ USER_ID = [[ user_id ]]

---

Get user

GET {{ API_ORIGIN }}/users/{{ USER_ID }}

^ & status == 200
& body.id -> $FETCHED_USER_ID
```

- The preamble goes before the first `---`
- Each request block starts after `---`
- Request titles are used in output and dependencies

## Variables and prompts

```hen
$ API_ORIGIN = https://api.example.com
$ TOKEN = $(./get_token.sh)
$ API_KEY = secret.env("HEN_API_KEY")
$ USER_ID = [[ user_id ]]
$ REGION = [[ region = us-east-1 ]]
$ USER = [alice,bob]
```

- `$ NAME = value` defines a reusable scalar
- `[[ name ]]` prompts for a value
- `[[ name = default ]]` prompts with a default
- `[a,b]` maps a request across multiple values

## Request target

```hen
GET https://example.com/users/123
POST {{ API_ORIGIN }}/users
```

The request line is usually `METHOD URL`.

## Headers, query params, and form fields

```hen
* Authorization = Bearer {{ API_KEY }}
? page = 1
~ avatar = @./avatar.png
~ role = admin
```

- `*` adds a header
- `?` adds a query parameter
- `~` adds a multipart form field

## Body blocks

```hen
~~~json
{"id":"123"}
~~~
```

```hen
~~~ application/json
{
  "username": "[[ username ]]"
}
~~~
```

Use `~~~` to start and end the request body.

## Assertions

```hen
^ & status == 200
^ & body.user.id == "123"
^ & body.total === NUMBER
^ & body.message ~= "ok"
```

- `^` starts an assertion
- `==` and `!=` compare values
- `~=` does structural or partial matching
- `===` validates against a schema target

## Captures

```hen
& body.user.id -> $USER_ID
& header.content_type -> $CONTENT_TYPE
& status -> $STATUS
```

Captures export response values for later requests.

## Dependencies

```hen
> requires: Login
```

Use dependencies when one request must run before another.

## Sessions and environments

```hen
session = web

env local
  $ API_ORIGIN = http://localhost:3000
```

- `session = ...` reuses runtime state like cookies or protocol sessions
- `env ...` defines named scalar overrides in the preamble

## Common commands

```bash
hen verify ./collection.hen
hen run ./collection.hen 0
hen run ./collection.hen all --non-interactive
hen inspect ./collection.hen --output json
```

## Read next

- [Interactive CLI]./interactive-cli.md
- [CLI Reference]../cli/reference.md
- [Language Reference]../reference/index.md