Write calls
A call file holds the HTTP calls a person would check, each named by the comment above it.
# The owner sees every itemGET {{api}}/itemsAuthorization: Bearer {{owner}}HTTP 200[Asserts]jsonpath "$.items" count == 3
# A member isn't told the admin page existsGET {{api}}/adminAuthorization: Bearer {{member}}HTTP 404
# Nobody is let in without a tokenGET {{api}}/itemsHTTP 401A comparison shows each call whose answer changed, and how.
$ 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.
Write a call
Section titled “Write a call”-
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: apiserviceis the service whose URL is{{api}}. Without it, Rehearse takes the default service: the one namedapi, else the first with a URL. -
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. -
Say who sends it.
Authorization: Bearer {{owner}}sends it asowner: Rehearse fills in that person’s token from the sign-in. A call with noAuthorizationis sent as nobody. -
Say what should come back:
HTTP 200(orHTTP *for any status), then[Asserts]. -
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 ownerGET /items/count as owner → 200stand-ins: payments (fake)line 30: jsonpath "$.count" == 3expected 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.
Use people and variables
Section titled “Use people and variables”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.
$ rehearse peopleowner (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, shopTokens never appear in what Rehearse keeps or prints: each one is written back as {{owner}}.
Capture a value for later calls
Section titled “Capture a value for later calls”A call can capture a value for the calls after it in the same file.
# The owner adds an itemPOST {{api}}/itemsAuthorization: Bearer {{owner}}{"name": "Pen", "price": 3.5}HTTP 201[Captures]item_id: jsonpath "$.id"
# The owner reads the item backGET {{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.
Wait for work that finishes later
Section titled “Wait for work that finishes later”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].
# The owner starts an exportPOST {{api}}/exportsAuthorization: Bearer {{owner}}{"kind": "stock"}HTTP 202[Captures]export_id: jsonpath "$.id"
# The export finishesGET {{api}}/exports/{{export_id}}Authorization: Bearer {{owner}}[Options]retry: 10retry-interval: 500msHTTP 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.
Check what Rehearse reads
Section titled “Check what Rehearse reads”| 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.
Avoid what is refused
Section titled “Avoid what is refused”Anything beyond the plain part is refused by name, with its line. rehearse check says so before anything runs.
✗ 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 RehearseThat 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.
Send a call by hand on the stage
Section titled “Send a call by hand on the stage”Start the stage from the repository.
rehearse stageChoose 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.
{"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.
Read next
Section titled “Read next”- Comparing base and head
- Scenario files reference: the call format in full.