@@ -33,7 +33,85 @@ jsonpath "$.id" matches /\d{4}/ # Check the format of the id
3333
3434## Generating Dynamic Values with Functions
3535
36- With Hurl 6.0.0, we have introduced [ functions]
36+ Before 6.0.0, Hurl files could be only [ templatized] with variables. Variables are either injected in the command line,
37+ in ` [Options] ` section or through [ captures] .
38+
39+ For instance, this Hurl file:
40+
41+ ``` hurl
42+ PUT https://example.org/api/hits
43+ Content-Type: application/json
44+ {
45+ "key0": "{{a_string}}",
46+ "key1": {{a_bool}},
47+ "key2": {{a_null}},
48+ "key3": {{a_number}}
49+ }
50+ ```
51+
52+ When called with these options:
53+
54+ ``` shell
55+ hurl --variable a_string=apple \
56+ --variable a_bool=true \
57+ --variable a_null=null \
58+ --variable a_number=42 \
59+ test.hurl
60+ ```
61+
62+ runs a PUT request with the following JSON body:
63+
64+ ```
65+ {
66+ "key0": "apple",
67+ "key1": true,
68+ "key2": null,
69+ "key3": 42
70+ }
71+ ```
72+
73+
74+ With Hurl 6.0.0, we have introduced [ functions] to generate dynamic values. Current functions are:
75+
76+ - ` newUuid ` to generate an [ UUID v4 random string] ,
77+ - ` newDate ` to generate an [ RFC 3339] UTC date string, at the current time.
78+
79+
80+ In the following example, we use ` newDate ` to generate a dynamic query parameter:
81+
82+ ``` hurl
83+ GET https://example.org/api/foo
84+ [QueryStringParams]
85+ date: {{newDate}}
86+ HTTP 200
87+ ```
88+
89+ We run a ` GET ` request to ` https://example.org/api/foo?date=2024%2D12%2D02T10%3A35%3A44%2E461731Z ` where the ` date `
90+ query parameter value is ` 2024-12-02T10:35:44.461731Z ` URL encoded.
91+
92+ In this second example, we use ` newUuid ` function to generate an email dynamically:
93+
94+ ``` hurl
95+ POST https://example.org/api/foo
96+ {
97+ "name": "foo",
98+ "email": "{{newUuid}}@test.com"
99+ }
100+ ```
101+
102+ When run, the request body will be:
103+
104+ ```
105+ {
106+ "name": "foo",
107+ 108+ }
109+ ```
110+
111+ We've started small with these two functions, but we plan to add many more; don't hesitate to open a discussion for
112+ your use case!
113+
114+
37115
38116
39117## curl Run Export
@@ -72,7 +150,8 @@ We'll be happy to hear from you, either for enhancement requests or for sharing
72150[ Hurl ] : https://hurl.dev
73151[ curl ] : https://curl.se
74152[ functions] : {% link _ docs/templates.md#functions %}
75-
153+ [ UUID v4 random string ] : https://en.wikipedia.org/wiki/Universally_unique_identifier
154+ [ RFC 3339 ] : https://www.rfc-editor.org/rfc/rfc3339
76155
77156[ in our release note ] : https://github.com/Orange-OpenSource/hurl/releases/tag/5.0.0
78157[ 𝕏 / Twitter ] : https://x.com/HurlDev
0 commit comments