Hurl HTTP requests as tests

Version 8.0.1 · source

Start here

hurl <file.hurl>
Run a file, print last body
hurl --test <file.hurl>
Run as test, show summary
hurl --variable <name>=<value> <file>
Inject a variable
hurl -v <file>
Show request and response
hurl --very-verbose <file>
Debug incl. bodies
hurl --test --report-html <dir> <files>
HTML test report
hurl --retry <n> <file>
Retry failed entries
hurl --glob "<pattern>"
Run files by pattern

Concepts

  1. Request METHOD URL, headers, body
  2. Response HTTP 200
  3. Variables {{name}}
  4. [Asserts] pass or fail, exit code

Run

hurl <file.hurl>
Run a file
hurl <a.hurl> <b.hurl>
Run several files in order
hurl --test <files>
Test mode: progress and summary
hurl --glob "<pattern>"
Run files matching a glob
hurl --continue-on-error <file>
Do not stop at the first failed assert
hurl --retry <n> --retry-interval <ms> <file>
Retry failed entries

Request

GET <url>
First line: method and URL
<Name>: <value>
Header lines straight after the URL
[Query] <key>: <value>
Query string params, unencoded
[Form] <key>: <value>
URL-encoded form fields
[BasicAuth] <user>: <password>
Basic authentication
[Options] <option>: <value>
Per-request options
{ "key": "value" }
JSON body, Content-Type set for you
```json ... ```
Multiline body, with templates

Response & Asserts

HTTP 200
Expect this status
[Asserts]
Section of checks, one per line
status < 300
Status check
header "<Name>" contains "<text>"
Header check
jsonpath "$.a.b" == "<value>"
Check a JSON value
jsonpath "$.items" count == <n>
Check list length
xpath "//h1" exists
Check HTML or XML
body contains "<text>"
Substring of the body
jsonpath "$.x" not exists
Negate any predicate with not

Predicates

== != > >= < <=
Compare values
startsWith endsWith contains
String and list checks
matches /<re>/
Regex match
exists isEmpty
Presence checks
isString isInteger isBoolean
Type checks (also isFloat, isList...)

Captures & Variables

[Captures]
Section that stores response values
id: jsonpath "$.id"
Capture a JSON value
tok: header "X-Token"
Capture a header
pass: header "token" redact
Hide a captured value in logs
{{name}}
Use a variable in URL, header, body
hurl --variable <name>=<value>
Set a variable
hurl --variables-file <file>
Variables from name=value lines
hurl --secret <name>=<value>
Variable redacted from logs

Filters

HTTP options

-L, --location
Follow redirects
-H, --header <Name:value>
Add a header to every request
-u, --user <user:password>
Basic authentication
-k, --insecure
Skip TLS verification
--compressed
Ask for and decode compression
--resolve <host:port:addr>
Override DNS for a host
-b <file> / -c <file>
Read or write cookies (Netscape)

Output & Reports

-v, --verbose
Request and response details on stderr
--very-verbose
Debug output with bodies
-i, --include
Print response headers too
-o, --output <file>
Write the body to a file
--json
Output results as JSON
--error-format long
Detailed error messages
-h, --help / -V, --version
Help and version
--report-html <dir>
HTML report
--report-junit <file>
JUnit XML for CI
Exit codes
Code Meaning
0 Success
1 Bad command-line options
2 Hurl file parse error
3 Runtime error (e.g. connection)
4 Assert failed

Recipes

Login, capture a token, call the API
POST https://api.example.com/login{ "user": "{{user}}", "pass": "{{pass}}" }HTTP 200[Captures]token: jsonpath "$.token" redactGET https://api.example.com/meAuthorization: Bearer {{token}}HTTP 200[Asserts]jsonpath "$.name" == "{{user}}"
Poll until a job is done
GET https://api.example.com/jobs/{{id}}[Options]retry: 10retry-interval: 2000HTTP 200[Asserts]jsonpath "$.status" == "done"
CI run with a JUnit report
hurl --test --variable host=https://staging.example.com \  --report-junit build/hurl.xml tests/*.hurl
Upload a file with a query parameter
POST https://api.example.com/upload[Query]folder: docs[Multipart]file: file,report.pdf; application/pdfHTTP 201