Skip to content
Rehearsev1.2.0

Write calls

A call file holds the HTTP calls a person would check, each named by the comment above it.

packages/api/items.hurl
# The owner sees every item
GET {{api}}/items
Authorization: Bearer {{owner}}
HTTP 200
[Asserts]
jsonpath "$.items" count == 3
# A member isn't told the admin page exists
GET {{api}}/admin
Authorization: Bearer {{member}}
HTTP 404
# Nobody is let in without a token
GET {{api}}/items
HTTP 401

A comparison shows each call whose answer changed, and how.

Terminal
$ rehearse compare --base main
…
changed without saying so:
The owner sees every item (packages/api/items.hurl:14)
$.items[*].price: 3.5 → "3.50" (3 places)

A call is one HTTP request a person would check, and what should come back. Rehearse reads Hurl’s plain part: the request, the status, captures and asserts. Each call in a file is its own scenario, named by the comment above it. Put the file beside the handler it tries.

  1. Point the manifest at your calls, and at the service they go to. List the call files under scenarios.calls.

    rehearse.yaml
    scenarios:
    calls:
    paths: ['apps/api/src/**/*.hurl']
    service: api

    service is the service whose URL is {{api}}. Without it, Rehearse takes the default service: the one named api, else the first with a URL.

  2. Name the call with a comment on the line right above its method. That name is its id in the file: packages/api/items.hurl#The owner sees every item. A call with no comment above it is named by its method and URL. Two calls with the same name in one file are refused.

  3. Say who sends it. Authorization: Bearer {{owner}} sends it as owner: Rehearse fills in that person’s token from the sign-in. A call with no Authorization is sent as nobody.

  4. Say what should come back: HTTP 200 (or HTTP * for any status), then [Asserts].

  5. Run it by its id, and read what came back.

    Terminal
    $ rehearse run 'packages/api/items.hurl#The count is right'
    ✗ The count is right (packages/api/items.hurl#The count is right)
    on …/shop at dc928d1a5199 · world stocked · as owner
    GET /items/count as owner → 200
    stand-ins: payments (fake)
    line 30: jsonpath "$.count" == 3
    expected 3, got 2

Rehearse compares the status, the content type and the body. A JSON body is compared by path, after setting aside ids, times and opaque values; any other body line by line. See what is set aside.

A call can use any of these as {{name}}:

Variable Is
{{api}} the calls service’s URL, without a trailing slash
{{owner}}, {{member}} each person’s token, from the sign-in
{{owner_role}} a field the sign-in printed beside a person’s token: <person>_<field>
{{shop}} a variable the sign-in printed under variables
your own scenarios.calls.variables in the manifest
{{api_url}}, {{api_port}}, {{url}} each running service’s URL and port, and the default service’s URL
{{checkout}}, {{manifest}}, {{world}} where it runs, and the world
a capture a value an earlier call in the same file captured

A variable with no value fails the call with {{name}} has no value, so a typo never sends a request with a hole in it.

--as member sends every call as member, whatever its Authorization says. --as nobody sends them with none.

rehearse people lists the people a call can be sent as, and the variables the sign-in gave.

Terminal
$ rehearse people
owner (default) — local: Runs the shop · token (16 characters, hidden; --json prints it)
member — local: A customer with an account · token (17 characters, hidden; --json prints it)
variables: owner_role, member_role, shop

Tokens never appear in what Rehearse keeps or prints: each one is written back as {{owner}}.

A call can capture a value for the calls after it in the same file.

apps/api/src/items.hurl
# The owner adds an item
POST {{api}}/items
Authorization: Bearer {{owner}}
{"name": "Pen", "price": 3.5}
HTTP 201
[Captures]
item_id: jsonpath "$.id"
# The owner reads the item back
GET {{api}}/items/{{item_id}}
Authorization: Bearer {{owner}}
HTTP 200
[Asserts]
jsonpath "$.name" == "Pen"

Calls in a file run in order. When you run or compare one call, Rehearse sends every call before it first, so its captures and its state are the ones it was written against. A capture that finds nothing fails the call that captures it.

A call’s definition includes the earlier calls whose captures it uses. Editing “The owner adds an item” counts as editing “The owner reads the item back” too.

Some requests start work and return at once: an export, an email, a job. Fire the work in one call, then watch for it in the next with [Options].

apps/api/src/exports.hurl
# The owner starts an export
POST {{api}}/exports
Authorization: Bearer {{owner}}
{"kind": "stock"}
HTTP 202
[Captures]
export_id: jsonpath "$.id"
# The export finishes
GET {{api}}/exports/{{export_id}}
Authorization: Bearer {{owner}}
[Options]
retry: 10
retry-interval: 500ms
HTTP 200
[Asserts]
jsonpath "$.state" == "done"

retry: 10 sends the call again, up to ten more times, while its status or an assert doesn’t hold. retry-interval waits between tries (500ms, 2s; one second by default). Retries are capped at 60. A retried call keeps the status of each try in its observation (tries).

[Options] goes before the HTTP line, with the request.

Part Read
Request GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS; headers; a body (JSON or text, or fenced with three backticks); [Query] (or [QueryStringParams]); [Options] with retry and retry-interval
Response HTTP <status> or HTTP *; header lines right after it (each must be equal); [Captures]; [Asserts]
Queries status, header "Name", body, duration, jsonpath "$…", each with an optional count
Predicates ==, !=, >, >=, <, <=, contains, includes, startsWith, endsWith, matches, exists, isString, isInteger, isBoolean, isCollection, isEmpty, isUuid, isIsoDate, each with an optional not
JSON paths $.a.b, $.items[0], $.items[*], $['a key'], $.items[?(@.role == 'owner')]

A body without a Content-Type header is sent as application/json when it starts with { or [, else as text. Redirects are not followed. A call that gets no answer in 15 seconds fails.

Anything beyond the plain part is refused by name, with its line. rehearse check says so before anything runs.

Terminal
✗ a.hurl:3: [BasicAuth] isn’t read by Rehearse: it reads Hurl’s plain part
✗ c.hurl:5: the filter split isn’t read by Rehearse

That covers sections such as [BasicAuth], [FormParams], [MultipartFormData] and [Cookies], filters other than count, options other than retry and retry-interval, queries such as xpath, and file,, base64,, hex, and XML bodies. The other calls in a refused file still aren’t read: fix the file, or move the call to its own.

Start the stage from the repository.

Terminal
rehearse stage

Choose a call, then Head or Base. The canvas shows the call in Hurl, in a box you can edit. Change the path, a header, the person, the body; then Send to the head (or base). The answer shows below: the status, the content type, who it was sent as, the body, and any assert that didn’t hold. Your edit stays while you look at other scenarios; Put back returns the call as its file has it.

The first send to a side brings that side’s services up, builds the world (the one chosen in World, else the default: its before, then its add) and signs everyone in. They stay up for the next send to the same side, so you can try one thing after another. As chooses the person, as --as does.

Each send answers one line of JSON. The following lines are one call sent to each side in turn.

What a send answers
{"v":1,"side":"head","request":"GET /items/count","who":"owner","status":200,"contentType":"application/json","body":{"count":2},"failures":[],"ms":18}
{"v":1,"side":"base","request":"GET /items/count","who":"owner","status":200,"contentType":"application/json","body":{"count":3},"failures":[],"ms":4}

A sent call is a try, not a scenario: nothing is written to your files. To keep it, copy it into the .hurl file.