2022-05-31 15:36:54 +03:00
|
|
|
# Entry
|
|
|
|
|
|
|
|
## Definition
|
|
|
|
|
2022-09-28 11:24:24 +03:00
|
|
|
A Hurl file is a list of entries, each entry being a mandatory [request], optionally followed by a [response].
|
2022-05-31 15:36:54 +03:00
|
|
|
|
|
|
|
Responses are not mandatory, a Hurl file consisting only of requests is perfectly valid. To sum up, responses can be used
|
|
|
|
to [capture values] to perform subsequent requests, or [add asserts to HTTP responses].
|
|
|
|
|
|
|
|
## Example
|
|
|
|
|
|
|
|
```hurl
|
|
|
|
# First, test home title.
|
|
|
|
GET https://acmecorp.net
|
|
|
|
|
|
|
|
HTTP/1.1 200
|
|
|
|
[Asserts]
|
|
|
|
xpath "normalize-space(//head/title)" == "Hello world!"
|
|
|
|
|
|
|
|
# Get some news, response description is optional
|
|
|
|
GET https://acmecorp.net/news
|
|
|
|
|
|
|
|
# Do a POST request without csrf token and check
|
|
|
|
# that status code is Forbidden 403
|
|
|
|
POST https://acmecorp.net/contact
|
|
|
|
[FormParams]
|
|
|
|
default: false
|
|
|
|
email: john.doe@rookie.org
|
|
|
|
number: 33611223344
|
|
|
|
|
|
|
|
HTTP/1.1 403
|
|
|
|
```
|
|
|
|
|
|
|
|
## Description
|
|
|
|
|
2022-10-24 21:58:56 +03:00
|
|
|
### Options
|
|
|
|
|
|
|
|
[Options] specified on the command line apply to every entry in an Hurl file. For instance, with [`--location` option],
|
|
|
|
every entry of a given file will follow redirection:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
$ hurl --location foo.hurl
|
|
|
|
```
|
|
|
|
|
|
|
|
You can use an [`[Options]` section] to use option only for a specified option. For instance, in this Hurl file:
|
|
|
|
|
|
|
|
```hurl
|
|
|
|
GET https://google.fr
|
|
|
|
HTTP/* 301
|
|
|
|
|
|
|
|
GET https://google.fr
|
|
|
|
[Options]
|
|
|
|
location: true
|
|
|
|
HTTP/* 200
|
|
|
|
|
|
|
|
GET https://google.fr
|
|
|
|
HTTP/* 301
|
|
|
|
```
|
|
|
|
|
|
|
|
The second entry will follow location (and so we can test the status code to be 200 instead of 301).
|
|
|
|
|
|
|
|
You can use it to logs a specific entry:
|
|
|
|
|
|
|
|
```hurl
|
|
|
|
# ... previous entries
|
|
|
|
|
|
|
|
GET https://api.example.org
|
|
|
|
[Options]
|
|
|
|
very-verbose: true
|
|
|
|
|
|
|
|
HTTP/* 200
|
|
|
|
|
|
|
|
# ... next entries
|
|
|
|
```
|
|
|
|
|
2022-05-31 15:36:54 +03:00
|
|
|
### Cookie storage
|
|
|
|
|
|
|
|
Requests in the same Hurl file share the cookie storage, enabling, for example, session based scenario.
|
|
|
|
|
|
|
|
### Redirects
|
|
|
|
|
|
|
|
By default, Hurl doesn't follow redirection. To effectively run a redirection, entries should describe each step
|
|
|
|
of the redirection, allowing insertion of asserts in each response.
|
|
|
|
|
|
|
|
```hurl
|
|
|
|
# First entry, test the redirection (status code and
|
|
|
|
# Location header)
|
2022-10-24 21:58:56 +03:00
|
|
|
GET https://google.fr
|
2022-05-31 15:36:54 +03:00
|
|
|
|
|
|
|
HTTP/1.1 301
|
2022-10-24 21:58:56 +03:00
|
|
|
Location: https://www.google.fr/
|
2022-05-31 15:36:54 +03:00
|
|
|
|
|
|
|
# Second entry, the 200 OK response
|
2022-10-24 21:58:56 +03:00
|
|
|
GET https://www.google.fr
|
2022-05-31 15:36:54 +03:00
|
|
|
|
|
|
|
HTTP/1.1 200
|
|
|
|
```
|
|
|
|
|
|
|
|
Alternatively, one can use [`--location`] option to force redirection
|
|
|
|
to be followed. In this case, asserts are executed on the last received response. Optionally, the number of
|
|
|
|
redirections can be limited with [`--max-redirs`].
|
|
|
|
|
|
|
|
```hurl
|
|
|
|
# Running hurl --location google.hurl
|
2022-10-24 21:58:56 +03:00
|
|
|
GET https://google.fr
|
2022-05-31 15:36:54 +03:00
|
|
|
HTTP/1.1 200
|
|
|
|
```
|
|
|
|
|
2022-10-24 21:58:56 +03:00
|
|
|
Finally, you can force redirection on a particular request with an [`[Options]` section][options] and the [`--location` option]:
|
2022-08-16 16:30:48 +03:00
|
|
|
|
|
|
|
```hurl
|
|
|
|
GET https://google.fr
|
|
|
|
[Options]
|
|
|
|
location: true
|
2022-10-24 21:58:56 +03:00
|
|
|
HTTP/1.1 200
|
2022-08-16 16:30:48 +03:00
|
|
|
```
|
|
|
|
|
2022-10-24 21:58:56 +03:00
|
|
|
### Retry
|
2022-08-16 16:30:48 +03:00
|
|
|
|
2022-10-24 21:58:56 +03:00
|
|
|
Every entry can be retried upon asserts, captures or runtime errors. Retries allow polling scenarios and effective runs
|
|
|
|
under flaky conditions. Asserts can be explicit (with an [`[Asserts]` section][asserts]), or implicit (like [headers] or [status code]).
|
|
|
|
|
|
|
|
Retries can be set globally for every request (see [`--retry`], [`--retry-interval`] and [`--retry-max-count`] options),
|
|
|
|
or activated on a particular request with an [`[Options]` section][options].
|
|
|
|
|
|
|
|
For example, in this Hurl file, first we create a new job, then we poll the new job until it's completed:
|
2022-08-16 16:30:48 +03:00
|
|
|
|
|
|
|
```hurl
|
2022-10-24 21:58:56 +03:00
|
|
|
# Create a new job
|
|
|
|
POST http://api.example.org/jobs
|
2022-08-16 16:30:48 +03:00
|
|
|
|
2022-10-24 21:58:56 +03:00
|
|
|
HTTP/* 201
|
|
|
|
[Captures]
|
|
|
|
job_id: jsonpath "$.id"
|
|
|
|
[Asserts]
|
|
|
|
jsonpath "$.state" == "RUNNING"
|
|
|
|
|
|
|
|
|
|
|
|
# Pull job status until it is completed
|
|
|
|
GET http://api.example.org/jobs/{{job_id}}
|
2022-08-16 16:30:48 +03:00
|
|
|
[Options]
|
2022-10-24 21:58:56 +03:00
|
|
|
retry: true
|
2022-08-16 16:30:48 +03:00
|
|
|
|
|
|
|
HTTP/* 200
|
2022-10-24 21:58:56 +03:00
|
|
|
[Asserts]
|
|
|
|
jsonpath "$.state" == "COMPLETED"
|
2022-08-16 16:30:48 +03:00
|
|
|
```
|
|
|
|
|
2022-10-24 21:58:56 +03:00
|
|
|
|
2022-05-31 15:36:54 +03:00
|
|
|
[request]: /docs/request.md
|
|
|
|
[response]: /docs/response.md
|
|
|
|
[capture values]: /docs/capturing-response.md
|
|
|
|
[add asserts to HTTP responses]: /docs/asserting-response.md
|
2022-09-02 15:45:54 +03:00
|
|
|
[`--location`]: /docs/manual.md#location
|
|
|
|
[`--max-redirs`]: /docs/manual.md#max-redirs
|
|
|
|
[Options]: /docs/manual.md#options
|
2022-10-24 21:58:56 +03:00
|
|
|
[options]: /docs/manual.md#options
|
2022-09-02 15:45:54 +03:00
|
|
|
[`--location` option]: /docs/manual.md#location
|
2022-10-24 21:58:56 +03:00
|
|
|
[headers]: /docs/response.md#headers
|
|
|
|
[status code]: /docs/response.md#version-status
|
|
|
|
[asserts]: /docs/response.md#asserts
|
|
|
|
[Asserts]: /docs/response.md#asserts
|
|
|
|
[`--retry`]: /docs/manual.md#retry
|
|
|
|
[`--retry-interval`]: /docs/manual.md#retry-interval
|
|
|
|
[`--retry-max-count`]: /docs/manual.md#retry-max-count
|
|
|
|
|