@@ -125,6 +125,160 @@ Set-Cookie: theme=light
125125If you want to test specifically the number of headers returned for a given header name, or if you want to test header
126126value with [ predicates] (like ` startsWith ` , ` contains ` , ` exists ` )you can use the explicit [ header assert] .
127127
128+ ### Body
129+
130+ Optional assertion on the received HTTP response body. Body section can be seen as syntactic sugar over [ body asserts]
131+ (with ` == ` predicate). If the body of the response is a [ JSON] string or a [ XML] string, the body assertion can be
132+ directly inserted without any modification. For a text based body that is neither JSON nor XML, one can use multiline
133+ string that starts with <code >` ;` ;` ; </code > and ends with <code >` ;` ;` ; </code >. For a precise byte
134+ control of the response body, a [ Base64] encoded string or an input file can be used to describe exactly the body byte
135+ content to check.
136+
137+ Like explicit [ ` body ` assert] , the body section is automatically decompressed based on the value of ` Content-Encoding `
138+ response header. So, whatever is the response compression (` gzip ` , ` brotli ` , etc...) body section doesn't depend on
139+ the content encoding. For textual body sections (JSON, XML, multiline, etc...), content is also decoded to string, based
140+ on the value of ` Content-Type ` response header.
141+
142+ #### JSON body
143+
144+ {% raw %}
145+ ``` hurl
146+ # Get a doggy thing:
147+ GET https://example.org/api/dogs/{{dog-id}}
148+ HTTP 200
149+ {
150+ "id": 0,
151+ "name": "Frieda",
152+ "picture": "images/scottish-terrier.jpeg",
153+ "age": 3,
154+ "breed": "Scottish Terrier",
155+ "location": "Lisco, Alabama"
156+ }
157+ ```
158+ {% endraw %}
159+
160+
161+ JSON response body can be seen as syntactic sugar of [ multiline string body] with ` json ` identifier:
162+
163+ {% raw %}
164+ ~~~ hurl
165+ # Get a doggy thing:
166+ GET https://example.org/api/dogs/{{dog-id}}
167+ HTTP 200
168+ ```json
169+ {
170+ "id": 0,
171+ "name": "Frieda",
172+ "picture": "images/scottish-terrier.jpeg",
173+ "age": 3,
174+ "breed": "Scottish Terrier",
175+ "location": "Lisco, Alabama"
176+ }
177+ ```
178+ ~~~
179+ {% endraw %}
180+
181+
182+ #### XML body
183+
184+ ~~~ hurl
185+ GET https://example.org/api/catalog
186+ HTTP 200
187+ <?xml version="1.0" encoding="UTF-8"?>
188+ <catalog>
189+ <book id="bk101">
190+ <author>Gambardella, Matthew</author>
191+ <title>XML Developer's Guide</title>
192+ <genre>Computer</genre>
193+ <price>44.95</price>
194+ <publish_date>2000-10-01</publish_date>
195+ <description>An in-depth look at creating applications with XML.</description>
196+ </book>
197+ </catalog>
198+ ~~~
199+
200+ XML response body can be seen as syntactic sugar of [ multiline string body] with ` xml ` identifier:
201+
202+ ~~~ hurl
203+ GET https://example.org/api/catalog
204+ HTTP 200
205+ ```xml
206+ <?xml version="1.0" encoding="UTF-8"?>
207+ <catalog>
208+ <book id="bk101">
209+ <author>Gambardella, Matthew</author>
210+ <title>XML Developer's Guide</title>
211+ <genre>Computer</genre>
212+ <price>44.95</price>
213+ <publish_date>2000-10-01</publish_date>
214+ <description>An in-depth look at creating applications with XML.</description>
215+ </book>
216+ </catalog>
217+ ```
218+ ~~~
219+
220+ #### Multiline string body
221+
222+ ~~~ hurl
223+ GET https://example.org/models
224+ HTTP 200
225+ ```
226+ Year,Make,Model,Description,Price
227+ 1997,Ford,E350,"ac, abs, moon",3000.00
228+ 1999,Chevy,"Venture ""Extended Edition""","",4900.00
229+ 1999,Chevy,"Venture ""Extended Edition, Very Large""",,5000.00
230+ 1996,Jeep,Grand Cherokee,"MUST SELL! air, moon roof, loaded",4799.00
231+ ```
232+ ~~~
233+
234+ The standard usage of a multiline string is :
235+
236+ ~~~
237+ ```
238+ line1
239+ line2
240+ line3
241+ ```
242+ ~~~
243+
244+ ##### Oneline string body
245+
246+ For text based response body that do not contain newlines, one can use oneline string, started and ending with <code >` ; </code >.
247+
248+ ~~~ hurl
249+ POST https://example.org/helloworld
250+ HTTP 200
251+ `Hello world!`
252+ ~~~
253+
254+ #### Base64 body
255+
256+ Base64 response body assert starts with ` base64, ` and end with ` ; ` . MIME's Base64 encoding is supported (newlines and
257+ white spaces may be present anywhere but are to be ignored on decoding), and ` = ` padding characters might be added.
258+
259+ ``` hurl
260+ GET https://example.org
261+ HTTP 200
262+ base64,TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIG
263+ FkaXBpc2NpbmcgZWxpdC4gSW4gbWFsZXN1YWRhLCBuaXNsIHZlbCBkaWN0dW0g
264+ aGVuZHJlcml0LCBlc3QganVzdG8gYmliZW5kdW0gbWV0dXMsIG5lYyBydXRydW
265+ 0gdG9ydG9yIG1hc3NhIGlkIG1ldHVzLiA=;
266+ ```
267+
268+ #### File body
269+
270+ To use the binary content of a local file as the body response assert, file body
271+ can be used. File body starts with ` file, ` and ends with `;``
272+
273+ ``` hurl
274+ GET https://example.org
275+ HTTP 200
276+ file,data.bin;
277+ ```
278+
279+ File are relative to the input Hurl file, and cannot contain implicit parent directory (` .. ` ). You can use [ ` --file-root ` option]
280+ to specify the root directory of all file nodes.
281+
128282## Explicit asserts
129283
130284Optional list of assertions on the HTTP response within an ` [Asserts] ` section. Assertions can describe checks
@@ -739,160 +893,6 @@ certificate "Expire-Date" daysAfterNow > 15
739893certificate "Serial-Number" matches "[0-9af]+"
740894```
741895
742- ## Body
743-
744- Optional assertion on the received HTTP response body. Body section can be seen as syntactic sugar over [ body asserts]
745- (with ` == ` predicate). If the body of the response is a [ JSON] string or a [ XML] string, the body assertion can be
746- directly inserted without any modification. For a text based body that is neither JSON nor XML, one can use multiline
747- string that starts with <code >` ;` ;` ; </code > and ends with <code >` ;` ;` ; </code >. For a precise byte
748- control of the response body, a [ Base64] encoded string or an input file can be used to describe exactly the body byte
749- content to check.
750-
751- Like explicit [ ` body ` assert] , the body section is automatically decompressed based on the value of ` Content-Encoding `
752- response header. So, whatever is the response compression (` gzip ` , ` brotli ` , etc...) body section doesn't depend on
753- the content encoding. For textual body sections (JSON, XML, multiline, etc...), content is also decoded to string, based
754- on the value of ` Content-Type ` response header.
755-
756- ### JSON body
757-
758- {% raw %}
759- ``` hurl
760- # Get a doggy thing:
761- GET https://example.org/api/dogs/{{dog-id}}
762- HTTP 200
763- {
764- "id": 0,
765- "name": "Frieda",
766- "picture": "images/scottish-terrier.jpeg",
767- "age": 3,
768- "breed": "Scottish Terrier",
769- "location": "Lisco, Alabama"
770- }
771- ```
772- {% endraw %}
773-
774-
775- JSON response body can be seen as syntactic sugar of [ multiline string body] with ` json ` identifier:
776-
777- {% raw %}
778- ~~~ hurl
779- # Get a doggy thing:
780- GET https://example.org/api/dogs/{{dog-id}}
781- HTTP 200
782- ```json
783- {
784- "id": 0,
785- "name": "Frieda",
786- "picture": "images/scottish-terrier.jpeg",
787- "age": 3,
788- "breed": "Scottish Terrier",
789- "location": "Lisco, Alabama"
790- }
791- ```
792- ~~~
793- {% endraw %}
794-
795-
796- ### XML body
797-
798- ~~~ hurl
799- GET https://example.org/api/catalog
800- HTTP 200
801- <?xml version="1.0" encoding="UTF-8"?>
802- <catalog>
803- <book id="bk101">
804- <author>Gambardella, Matthew</author>
805- <title>XML Developer's Guide</title>
806- <genre>Computer</genre>
807- <price>44.95</price>
808- <publish_date>2000-10-01</publish_date>
809- <description>An in-depth look at creating applications with XML.</description>
810- </book>
811- </catalog>
812- ~~~
813-
814- XML response body can be seen as syntactic sugar of [ multiline string body] with ` xml ` identifier:
815-
816- ~~~ hurl
817- GET https://example.org/api/catalog
818- HTTP 200
819- ```xml
820- <?xml version="1.0" encoding="UTF-8"?>
821- <catalog>
822- <book id="bk101">
823- <author>Gambardella, Matthew</author>
824- <title>XML Developer's Guide</title>
825- <genre>Computer</genre>
826- <price>44.95</price>
827- <publish_date>2000-10-01</publish_date>
828- <description>An in-depth look at creating applications with XML.</description>
829- </book>
830- </catalog>
831- ```
832- ~~~
833-
834- ### Multiline string body
835-
836- ~~~ hurl
837- GET https://example.org/models
838- HTTP 200
839- ```
840- Year,Make,Model,Description,Price
841- 1997,Ford,E350,"ac, abs, moon",3000.00
842- 1999,Chevy,"Venture ""Extended Edition""","",4900.00
843- 1999,Chevy,"Venture ""Extended Edition, Very Large""",,5000.00
844- 1996,Jeep,Grand Cherokee,"MUST SELL! air, moon roof, loaded",4799.00
845- ```
846- ~~~
847-
848- The standard usage of a multiline string is :
849-
850- ~~~
851- ```
852- line1
853- line2
854- line3
855- ```
856- ~~~
857-
858- #### Oneline string body
859-
860- For text based response body that do not contain newlines, one can use oneline string, started and ending with <code >` ; </code >.
861-
862- ~~~ hurl
863- POST https://example.org/helloworld
864- HTTP 200
865- `Hello world!`
866- ~~~
867-
868- ### Base64 body
869-
870- Base64 response body assert starts with ` base64, ` and end with ` ; ` . MIME's Base64 encoding is supported (newlines and
871- white spaces may be present anywhere but are to be ignored on decoding), and ` = ` padding characters might be added.
872-
873- ``` hurl
874- GET https://example.org
875- HTTP 200
876- base64,TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIG
877- FkaXBpc2NpbmcgZWxpdC4gSW4gbWFsZXN1YWRhLCBuaXNsIHZlbCBkaWN0dW0g
878- aGVuZHJlcml0LCBlc3QganVzdG8gYmliZW5kdW0gbWV0dXMsIG5lYyBydXRydW
879- 0gdG9ydG9yIG1hc3NhIGlkIG1ldHVzLiA=;
880- ```
881-
882- ### File body
883-
884- To use the binary content of a local file as the body response assert, file body
885- can be used. File body starts with ` file, ` and ends with `;``
886-
887- ``` hurl
888- GET https://example.org
889- HTTP 200
890- file,data.bin;
891- ```
892-
893- File are relative to the input Hurl file, and cannot contain implicit parent directory (` .. ` ). You can use [ ` --file-root ` option]
894- to specify the root directory of all file nodes.
895-
896896[ predicates ] : #predicates
897897[ header assert ] : #header-assert
898898[ captures] : {% link _ docs/capturing-response.md %}#query
0 commit comments