Skip to content

Commit ce3e750

Browse files
committed
add variable example doc
- move existing variable docs from http to variables example - document format update - links update - sidebar entry for variable examples
1 parent 36cfd08 commit ce3e750

5 files changed

Lines changed: 99 additions & 58 deletions

File tree

docs/examples/http-examples.md

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ Case-wise more example can be found in [https://github.com/chkware/cli](https://
1313

1414
[Http specification document reference](/references/http-reference)
1515

16-
## Request examples
17-
1816
Following examples are using HTTP _GET_ and _POST_ method. Although all these example are still valid for _POST_, _PUT_, _PATCH_, _DELETE_, _OPTIONS_, _HEAD_ method as well. You can still send a request body with _GET_ or _HEAD_ method for the sake of testing API.
1917

2018
### Minimal request with HTTP GET method
@@ -256,54 +254,3 @@ request:
256254
</book>
257255
</catalog>
258256
```
259-
260-
---
261-
## Request using variable examples
262-
263-
We can also use variables inside a http specification file. See examples below.
264-
265-
** * This is highly experimental. Report any bug you can find.**
266-
267-
### Request with query string using variables
268-
269-
```yaml
270-
---
271-
version: default:http:0.7.2
272-
273-
# define local variables
274-
variables:
275-
Foo: 'bar'
276-
Two: 2
277-
Server: https://example.org/api
278-
279-
request:
280-
# put variables on the path for query string
281-
url: {$Server}/path?foo={$Foo}&two={$Two}
282-
method: GET
283-
```
284-
285-
### Request with basic authentication header using variables
286-
287-
```yaml
288-
---
289-
version: default:http:0.7.2
290-
291-
# define local variables
292-
variables:
293-
userName: Some_USER
294-
password: Some-P@$$W03D
295-
content_type: application/json
296-
Server: https://example.org/api
297-
298-
request:
299-
url: {$Server}/resource/id
300-
method: GET
301-
302-
headers:
303-
Accept-Encoding: gzip, deflate
304-
Content-Type: {$content_type}
305-
306-
auth[basic]:
307-
username: {$userName}
308-
password: {$password}
309-
```

docs/examples/testcase-examples.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@ Case-wise more example can be found in [https://github.com/chkware/cli](https://
1313

1414
[Testcase specification document reference](/references/testcase-reference)
1515

16-
## Testcase examples:
17-
1816
Testcase is an experimental feature, in _`PRE_ALPHA`_ stage.
1917

20-
2118
### Testcase with in-file request
2219

2320
```yaml

docs/examples/variable-examples.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
title: Variable examples
3+
---
4+
5+
:::note
6+
- This page should be use as reference for specification files.
7+
- This page is subject to change. It is requested to check this page frequently.
8+
:::
9+
10+
:::note
11+
Case-wise more example can be found in [https://github.com/chkware/cli](https://github.com/chkware/cli/tree/main/tests/resources/storage/sample_config/pass_cases/variables) repository
12+
:::
13+
14+
[Variable specification document reference](/references/variable-reference)
15+
16+
We can also use variables inside a http and testcase specification file. See examples below.
17+
18+
** * This is highly experimental. Report any bug you can find.**
19+
20+
### Request with query string using variables
21+
22+
```yaml
23+
---
24+
version: default:http:0.7.2
25+
26+
# define local variables
27+
variables:
28+
Foo: 'bar'
29+
Two: 2
30+
Server: https://example.org/api
31+
32+
request:
33+
# put variables on the path for query string
34+
url: {$Server}/path?foo={$Foo}&two={$Two}
35+
method: GET
36+
37+
```
38+
39+
### Request with basic authentication header using variables
40+
41+
```yaml
42+
---
43+
version: default:http:0.7.2
44+
45+
# define local variables
46+
variables:
47+
userName: Some_USER
48+
password: Some-P@$$W03D
49+
content_type: application/json
50+
Server: https://example.org/api
51+
52+
request:
53+
url: {$Server}/resource/id
54+
method: GET
55+
56+
headers:
57+
Accept-Encoding: gzip, deflate
58+
Content-Type: {$content_type}
59+
60+
auth[basic]:
61+
username: {$userName}
62+
password: {$password}
63+
64+
```
65+
66+
### Testcase using variables
67+
68+
```yaml
69+
---
70+
version: 'default:testcase:0.7.2'
71+
72+
variables:
73+
Name: 'Morpheus'
74+
Job: 'leader'
75+
Response: ~
76+
Server: https://reqres.in/api/v1
77+
78+
request:
79+
url: "{$Server}/users"
80+
method: POST
81+
body[json]: {
82+
'name': $Name,
83+
'job': $Job,
84+
}
85+
return: ~
86+
87+
spec:
88+
execute:
89+
file: ~
90+
result: $Response
91+
92+
asserts:
93+
- {type: AssertEqual, actual: $Response.code, expected: 201}
94+
- {type: AssertIsMap, actual: $Response.body}
95+
96+
```

docs/references/variable-reference.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ Variables can be defined in two ways:
2828

2929
### Supported specification document
3030

31-
- [Http specification document examples](/examples/http-examples#variable-examples) | [More example](https://github.com/chkware/cli/tree/0272b83c2975349fd3f0d94e1646cc27b603eaf5/tests/resources/storage/sample_config/pass_cases/variables)
32-
- [Testcase specification document examples](/examples/testcase-examples) | [More example](https://github.com/chkware/cli/tree/890c2a6c11c5b16be4678ac27083befa1ef0986c/tests/resources/storage/sample_config/pass_cases/UserCreate)
31+
- [Http specification document examples](/examples/http-examples#variable-examples) | [More example](https://github.com/chkware/cli/tree/main/tests/resources/storage/sample_config/pass_cases/variables)
32+
- [Testcase specification document examples](/examples/testcase-examples) | [More example](https://github.com/chkware/cli/tree/main/tests/resources/storage/sample_config/pass_cases/UserCreate)

sidebars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const sidebars = {
2525
items: [
2626
'examples/http-examples',
2727
'examples/testcase-examples',
28+
'examples/variable-examples',
2829
],
2930
},
3031
{

0 commit comments

Comments
 (0)