hen 0.21.0

Run protocol-aware API request collections from the command line or through MCP.
Documentation
---
sidebar_position: 9
title: Dependencies, Fragments, and Callbacks
description: Reuse fragments, order requests explicitly, and run callbacks after execution.
---

## Dependencies

```hen
> requires: Request Name
```

Dependencies create a DAG so setup requests run before dependents. Dependency captures require the
referenced request to be declared in `> requires:` so the planner can guarantee the upstream result
exists.

Use dependencies when later requests need values or ordering guarantees from earlier requests.

When both sides are mapped requests, Hen resolves `> requires:` to the single expanded iteration
whose bindings are compatible with the dependent request. Unmapped requests still cannot depend on
an entire mapped request, and ambiguous mapped matches still fail.

## Fragments

```hen
<< ./fragments/common_schema_types.hen
[ FEATURE_ENABLED == true ] << ./fragments/extra_assertions.hen
```

- `<< path.hen` imports another Hen file before parsing
- fragment paths resolve relative to the importing file
- guards can skip a fragment import entirely
- fragments can contribute reusable declarations or request-local snippets

## Callbacks

```hen
! callback code
! ./path/to/callback_file.sh
! some command -> $VARIABLE_NAME
```

- callback assignments require whitespace around `->`
- assignment form suppresses stdout and exports the captured value
- callbacks run after request execution

Callbacks are a good fit for side effects such as notifications, local file writes, or shell-based
post-processing that should happen after a request completes.

## Combined Pattern

```hen
<< ./fragments/export_shapes.hen

---

Create export

POST {{ API_ORIGIN }}/exports

~~~json
{"format":"csv"}
~~~

^ & status == 202
& body.id -> $EXPORT_ID

---

Wait for export

> requires: Create export
GET {{ API_ORIGIN }}/exports/{{ EXPORT_ID }}

^ & status == 200
^ & body === ExportStatus

! ./scripts/notify_export_ready.sh
```

In that flow, the fragment can contribute shared variables or schema targets such as
`API_ORIGIN` and `ExportStatus`, the first request captures `$EXPORT_ID`, the second request uses
that capture through an explicit dependency, and the callback script runs after the dependent
request completes.

Dependencies, fragments, and callbacks work well together when you want:

- a reusable shared preamble
- a setup request that exports values
- a later request that consumes those values
- a callback that ships the result elsewhere after the request completes