Skip to content

Commit 36c28c9

Browse files
committed
Variable spec.
- definition doc - example doc
1 parent 675e654 commit 36c28c9

2 files changed

Lines changed: 85 additions & 0 deletions

File tree

docs/04-Examples/041-http-examples.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ title: Http spec. examples
1111
Case-wise more example can be found in `tests/resources/storage/sample_config` directory of [https://github.com/chkware/cli](https://github.com/chkware/cli/tree/main/tests/resources/storage/sample_config) repository
1212
:::
1313

14+
15+
## Request examples
16+
1417
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.
1518

1619
### Minimal request with HTTP GET method
@@ -252,3 +255,54 @@ request:
252255
</book>
253256
</catalog>
254257
```
258+
259+
---
260+
## Request using variable examples
261+
262+
We can also use variables inside a http specification file. See examples below.
263+
264+
** * This is highly experimental. Report any bug you can find.**
265+
266+
### Request with query string using variables
267+
268+
```yaml
269+
---
270+
version: default:http:0.7.2
271+
272+
# define local variables
273+
variables:
274+
Foo: 'bar'
275+
Two: 2
276+
Server: https://example.org/api
277+
278+
request:
279+
# put variables on the path for query string
280+
url: {$Server}/path?foo={$Foo}&two={$Two}
281+
method: GET
282+
```
283+
284+
### Request with basic authentication header using variables
285+
286+
```yaml
287+
---
288+
version: default:http:0.7.2
289+
290+
# define local variables
291+
variables:
292+
userName: Some_USER
293+
password: Some-P@$$W03D
294+
content_type: application/json
295+
Server: https://example.org/api
296+
297+
request:
298+
url: {$Server}/resource/id
299+
method: GET
300+
301+
headers:
302+
Accept-Encoding: gzip, deflate
303+
Content-Type: {$content_type}
304+
305+
auth[basic]:
306+
username: {$userName}
307+
password: {$password}
308+
```
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: Variable specification reference
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+
### Introduction
11+
12+
Variables are ways to hold value or computed values, like in programming language.
13+
14+
### Definition
15+
16+
Variables can be defined in two ways:
17+
18+
1. Variable specification file. Files with `version: default:variable:x.x.x` [**WIP**]
19+
2. `variables` section on a supported specification document. See below.
20+
```yaml
21+
version: default:http:0.7.2
22+
23+
variables:
24+
var1: value one
25+
var_2: 'value 2'
26+
...
27+
```
28+
29+
### Supported specification document
30+
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)

0 commit comments

Comments
 (0)