Hurl, run and test HTTP requests with plain text.
Go to file
Fabrice Reix 7537d11cb8
Merge pull request #29 from Orange-OpenSource/feature/request-cookie-not-in-cookie-storage
Request cookies must not change the cookie storage
2020-09-23 21:17:24 +02:00
ci rustfmt all your existing code! 2020-09-20 09:17:34 +02:00
docs Fix variable option anchor 2020-09-09 22:16:47 +02:00
integration Request cookies must not change the cookie storage 2020-09-23 20:35:00 +02:00
src Request cookies must not change the cookie storage 2020-09-23 20:35:00 +02:00
tests rustfmt all your existing code! 2020-09-20 09:17:34 +02:00
.gitignore Init Commit - beta release 0.99.12 2020-08-27 16:44:57 +02:00
.travis.yml Distinguish Job Build vs Release 2020-09-19 21:17:28 +02:00
build.rs rustfmt all your existing code! 2020-09-20 09:17:34 +02:00
build.sh rustfmt all your existing code! 2020-09-20 09:17:34 +02:00
Cargo.lock remove dependencies reqwest, percent-encoding and cookie 2020-09-17 19:55:25 +02:00
Cargo.toml remove dependencies reqwest, percent-encoding and cookie 2020-09-17 19:55:25 +02:00
LICENSE.md Init Commit - beta release 0.99.12 2020-08-27 16:44:57 +02:00
README.md Add samples on the README to give a quick feedback on Hurl syntax. 2020-09-04 21:13:56 +02:00


deploy status documentation

What's Hurl?

Hurl is a command line tool that performs HTTP requests defined in a simple plain text format.

It can perform requests, capture values and evaluate queries on headers and body response. Hurl is very versatile: it can be used for both fetching data and testing HTTP sessions.

# Get home:
GET https://example.net

HTTP/1.1 200
[Captures]
csrf_token: xpath "string(//meta[@name='_csrf_token']/@content)"

# Do login!
POST https://example.net/login?user=toto&password=1234
X-CSRF-TOKEN: {{csrf_token}}

HTTP/1.1 302

Chaining multiple requests is easy:

GET https://api.example.net/health
GET https://api.example.net/health
GET https://api.example.net/health
GET https://api.example.net/health

Also an HTTP Test Tool

Hurl can run HTTP requests but can also be used to test HTTP responses. Different type of queries and predicates are supported, from XPath and JSONPath on body response, to assert on status code and response headers.

GET https://example.net

HTTP/1.1 200
[Asserts]
xpath "normalize-space(//head/title)" equals "Hello world!"

It is well adapted for REST/json apis

POST https://api.example.net/tests
{
    "id": "456",
    "evaluate": true
}

HTTP/1.1 200
[Asserts]
jsonpath "$.status" equals "RUNNING"      # Check the status code
jsonpath "$.tests" countEquals 25         # Check the number of items

and even SOAP apis

POST https://example.net/InStock
Content-Type: application/soap+xml; charset=utf-8
SOAPAction: "http://www.w3.org/2003/05/soap-envelope"
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:m="http://www.example.org">
  <soap:Header></soap:Header>
  <soap:Body>
    <m:GetStockPrice>
      <m:StockName>GOOG</m:StockName>
    </m:GetStockPrice>
  </soap:Body>
</soap:Envelope>

HTTP/1.1 200

Documentation

Visit the Hurl web site to find out how to install and use Hurl.

Samples

Getting Data

A simple GET:

GET https://example.net

Doc

A simple GET with headers:

GET https://example.net/news
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:70.0) Gecko/20100101 Firefox/70.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Connection: keep-alive

Doc

Query Params

GET https://example.net/news
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:70.0) Gecko/20100101 Firefox/70.0
[QueryStringParams]
order: newest
search: something to search
count: 100

Or:

GET https://example.net/news?order=newest&search=something%20to%20search&count=100
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:70.0) Gecko/20100101 Firefox/70.0

Doc

Sending Data

Sending HTML Form Datas

POST https://example.net/contact
[FormParams]
default: false
token: {{token}}
email: john.doe@rookie.org
number: 33611223344

Doc

Sending Multipart Form Datas

POST https://example.net/upload
[MultipartFormData]
field1: value1
field2: file,example.txt;
# On can specify the file content type:
field3: file,example.zip; application/zip

Doc

Posting a JSON Body

With an inline JSON:

POST https://api.example.net/tests
{
    "id": "456",
    "evaluate": true
}

Doc

With a local file:

POST https://api.example.net/tests
Content-Type: application/json
file,data.json;

Doc

Templating a JSON/XML Body

Using templates with JSON body or XML body is not currently supported in Hurl. Besides, you can use templates in raw string body with variables to send a JSON or XML body:

PUT https://api.example.net/hits
Content-Type: application/json
```
{
    "key0": "{{a_string}}",
    "key1": {{a_bool}},
    "key2": {{a_null}},
    "key3": {{a_number}}
}
```

Variables can be initialized via command line:

$ hurl --variable key0=apple --variable key1=true --variable key2=null --variable key3=42 test.hurl

Resulting in a PUT request with the following JSON body:

{
    "key0": "apple",
    "key1": true,
    "key2": null,
    "key3": 42
}

Doc

Testing Response

Testing REST Apis

GET https//example.org/order
screencapability: low

HTTP/1.1 200
[Asserts]
jsonpath "$.validated" equals true
jsonpath "$.userInfo.firstName" equals "Franck"
jsonpath "$.userInfo.lastName" equals "Herbert"
jsonpath "$.hasDevice" equals false
jsonpath "$.links" countEquals 12

Doc

Testing HTML Response

GET https://example.com

HTTP/1.1 200
Content-Type: text/html; charset=UTF-8

[Asserts]
xpath "string(/html/head/title)" contains "Example" # Check title
xpath "count(//p)" equals 2                         # Check the number of p
xpath "//p" countEquals 2                           # Similar assert for p
xpath "boolean(count(//h2))" equals false           # Check there is no h2  
xpath "//h2" not exists                             # Similar assert for h2

Doc

Others

Using SOAP Apis

POST https://example.net/InStock
Content-Type: application/soap+xml; charset=utf-8
SOAPAction: "http://www.w3.org/2003/05/soap-envelope"
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:m="http://www.example.org">
  <soap:Header></soap:Header>
  <soap:Body>
    <m:GetStockPrice>
      <m:StockName>GOOG</m:StockName>
    </m:GetStockPrice>
  </soap:Body>
</soap:Envelope>

HTTP/1.1 200

Doc

Capturing and Using a CSRF Token

GET https://example.net

HTTP/* 200
[Captures]
csrf_token: xpath "string(//meta[@name='_csrf_token']/@content)"

POST https://example.net/login?user=toto&password=1234
X-CSRF-TOKEN: {{csrf_token}}

HTTP/* 302

Doc

Feedbacks

Hurl is still in beta, any feedback, suggestion, bugs or improvements are welcome.

POST https://hurl.dev/api/feedback
{
    "name": "John Doe",
    "feedback": "Hurl is awesome !"
}
HTTP/1.1 200