Skip to content

Commit 8fd222d

Browse files
committed
Update doc with raw multiline and escape behavior.
1 parent 13f4f31 commit 8fd222d

File tree

1 file changed

+60
-8
lines changed

1 file changed

+60
-8
lines changed

docs/request.md

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ very-verbose: true # allow more verbose output
233233
> Variable defined in an `[Options]` section are defined also for the next entries. This is
234234
> the exception, all other options are defined only for the current request.
235235
236-
237236
### Query parameters
238237

239238
Optional list of query parameters.
@@ -349,7 +348,6 @@ Content-Type: text/html
349348

350349
> When using a multiline string body to send a multipart form data, files content must be inlined in the Hurl file.
351350
352-
353351
### Cookies
354352

355353
Optional list of session cookies for this request.
@@ -455,6 +453,18 @@ POST https://example.org/api/cats
455453
}
456454
```
457455

456+
Escapes are not processed (and particularly [Hurl Unicode literals] are not supported): `\n` is two consecutive
457+
chars (`\` followed by a `n`), not a single newline char:
458+
459+
```hurl
460+
# Create a new catty thing with JSON body:
461+
POST https://example.org/api/cats
462+
{
463+
"text1": "\n is two chars \ and n",
464+
"text2": "\u{1D11E} is nine chars"
465+
}
466+
```
467+
458468

459469
When using JSON request body, the content type `application/json` is automatically set.
460470

@@ -475,7 +485,19 @@ POST https://example.org/api/dogs
475485
```
476486
~~~
477487

488+
If you don't want templates to be evaluated inside JSON body you can use [multiline string body] with `raw` identifier:
478489

490+
~~~hurl
491+
# {{name}} is not a variable
492+
POST https://example.org/api/cats
493+
Content-Type: application/json
494+
```raw
495+
{
496+
"id": 42,
497+
"name": "{{ name }}"
498+
}
499+
```
500+
~~~
479501

480502
#### XML body
481503

@@ -498,6 +520,8 @@ SOAPAction: "http://www.w3.org/2003/05/soap-envelope"
498520
</soap:Envelope>
499521
~~~
500522

523+
Like JSON body, escapes are not processed (`\n` is two consecutive `\` followed by a `n`).
524+
501525
XML request body can be seen as syntactic sugar of [multiline string body] with `xml` identifier:
502526

503527
~~~hurl
@@ -576,7 +600,6 @@ POST https://example.org/starwars/graphql
576600

577601
> Hurl variables and GraphQL variables can be mixed in the same body.
578602
579-
580603
#### Multiline string body
581604

582605
For text based body that are neither JSON nor XML, one can use multiline string, started and ending with
@@ -605,7 +628,23 @@ line3
605628

606629
is evaluated as "line1\nline2\nline3\n".
607630

608-
Multiline string body can use language identifier, like `json`, `xml` or `graphql`. Depending on the language identifier,
631+
Multiline string body can be [templatized with variables]:
632+
633+
~~~hurl
634+
POST https://example.org/models
635+
[Options]
636+
var1: lemon
637+
var2: yellow
638+
```
639+
Fruit,Color
640+
{{var1}},{{var2}}
641+
```
642+
~~~
643+
644+
Escapes are not processed (i.e. [Hurl Unicode literals] are not supported): `\n` is two consecutive
645+
chars (`\` followed by a `n`), not a single newline char.
646+
647+
Multiline string body can use language identifier, like `json`, `xml`, `graphql` or `raw`. Depending on the language identifier,
609648
an additional 'Content-Type' request header is sent, and the real body (bytes sent over the wire) can be different from the
610649
raw multiline text.
611650

@@ -614,7 +653,22 @@ POST https://example.org/api/dogs
614653
```json
615654
{
616655
"id": 0,
617-
"name": "Frieda",
656+
"name": "Frieda"
657+
}
658+
```
659+
~~~
660+
661+
Raw multiline string body don't evaluate templates:
662+
663+
~~~hurl
664+
# {{name}} is not a variable
665+
POST https://example.org/api/cats
666+
Content-Type: application/json
667+
```raw
668+
{
669+
"id": 42,
670+
"lives": {{ lives_count }},
671+
"name": "{{ name }}"
618672
}
619673
```
620674
~~~
@@ -628,7 +682,6 @@ POST https://example.org/helloworld
628682
`Hello world!`
629683
~~~
630684

631-
632685
#### Base64 body
633686

634687
Base64 body is used to set binary data as the request body.
@@ -657,7 +710,6 @@ PUT https://example.org
657710
hex,636166c3a90a;
658711
```
659712

660-
661713
#### File body
662714

663715
To use the binary content of a local file as the body request, file body can be used. File body starts with
@@ -705,4 +757,4 @@ File are relative to the input Hurl file, and cannot contain implicit parent dir
705757
[GraphQL queries]: #graphql-query
706758
[GraphQL variables]: https://graphql.org/learn/queries/#variables
707759
[options]: #options
708-
760+
[Hurl Unicode literals]: /docs/hurl-file.md#special-characters-in-strings

0 commit comments

Comments
 (0)