Skip to content

Commit 2312490

Browse files
committed
http spec. and reference updated
1 parent 52281d0 commit 2312490

2 files changed

Lines changed: 50 additions & 45 deletions

File tree

docs/examples/http-examples.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ request:
5151
two: 2
5252

5353
# get only response code
54-
return: .code
54+
expose:
55+
- $_response.code
5556
```
5657
5758
### Request with query string and header
@@ -149,8 +150,9 @@ request:
149150
150151
body[json]: { user_id: 32, roll_no: 1, class: 2, name: 'Student name' }
151152
152-
# get every thing out of response received
153-
return: ~
153+
# get every thing out of response received
154+
# not writing the following statement also does similar behavior
155+
expose: ~
154156
```
155157

156158
### Request with form
@@ -185,8 +187,8 @@ request:
185187
# but will not upload the actual file
186188
photo: file:///home/username/student-photo-01.png
187189
188-
# get only response body; response headers, code, etc will be dropped
189-
return: .body
190+
# get only response body; response headers, code, etc will be dropped
191+
expose: $_response.body
190192
```
191193

192194
### Request with file upload

docs/references/http-reference.md

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,45 @@ title: Http specification reference
77
- This page is subject to change. It is requested to check this page frequently.
88
:::
99

10-
The Http specification format is how anyone express a Http request. Following is the full reference to write Http specification file.
10+
The **Http specification format** is how anyone express a Http request. Following is the full reference to write Http specification file.
1111

12-
Http specification document is a versioned document, meaning there MUST be a `version:` key on the document.
12+
Http specification document is a _**versioned document**_, meaning there MUST be a `version:` key on the document.
1313

14-
> [TBD] It's also an exposable document meaning, you can expose local variables to whatever other spec. document it's called from.
14+
It's also an _**exposable document**_ meaning you can expose local data using `expose:` key in the document. More on this in [variable spec. reference](/references/variable-reference)
1515

16-
### Reference as example
16+
### All supported nodes in http specification document
1717

1818
```yaml
19+
# Version of the document
20+
version: "default:http:X.X.X"
21+
22+
# Define HTTP request with this node
1923
request:
2024
# valid URL
2125
url: https://httpbin.org/get
2226

23-
# for query string or url parameters
27+
# To be used for query string or url parameters
28+
# above URL becomes https://httpbin.org/get?one=1&two=true
2429
url_params:
2530
one: 1
2631
two: true
2732

28-
# http method to use
33+
# Http method to use
2934
method: GET # or POST, PUT, PATCH, DELETE, OPTIONS, HEAD
3035

31-
# send requst headers
32-
# add any numbers of headers
33-
# Causion: some values or keys need to be wrapped with single (') or double (") quote
36+
# Send request headers, add any numbers of headers
37+
# Caution: some values or keys need to be wrapped with single (') or double (") quote
38+
# Please use quotation marks substitution
3439
headers:
3540
User-Agent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36'
3641
'Accept-Encoding': 'gzip, deflate'
3742
accept: '*/*'
3843

39-
# ==== send authentication header ====
44+
# ==== Send authentication header ====
4045
# two supported type: auth[bearer], auth[basic]
4146

4247
# auth[bearer] example
48+
# Send a bearer token this way
4349
auth[bearer]:
4450
token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
4551

@@ -48,8 +54,14 @@ request:
4854
username: Some_USER
4955
password: 'Some-P@$$W03D'
5056

51-
# ==== send request body with the request ====
52-
# There are 5 supported type: body[form], body[form-data], body[json], body[xml], body[text]
57+
# ==== Send request body with the request ====
58+
# There are 5 supported form type:
59+
#
60+
# body[form] -> Send encoded form body with the request
61+
# body[form-data] -> Send multipart body with the request
62+
# body[json] -> Send JSON body with the request
63+
# body[xml] -> Send XML body with the request
64+
# body[text] -> Send plain text body with the request
5365

5466
# to send application/x-www-form-urlencoded form enctype
5567
body[form]:
@@ -103,26 +115,23 @@ request:
103115
</book>
104116
</catalog>
105117
106-
# returns given part of the response after
107-
# the request have been executed and got response
108-
#
109-
# supported values: 'version', 'code', 'reason', 'headers', 'body'
110-
# if not available, or set as null, returns all parts of response
111-
return: ~
118+
expose: ~
112119
```
113120
114121
---
115122
### `version` (<small>_`required`_</small>)
116123

117-
`version` is a top-level block that defines a document version. How to write a `version:` block, is [already defined here](/references/version-reference).
124+
`version` is a top-level block that defines a document version. How to write a `version:` block is already defined in [_version reference_](/references/version-reference).
118125

119126
### `variables`
120127

121-
`variables` is a top-level block that defines local variables. These variables are file scoped. How to write a `variables:` block, is [already defined here](/references/variable-reference).
128+
`variables` is a top-level block that defines local variables. These variables are file scoped. How to write a `variables:` block is already defined in [_variable-reference_](/references/variable-reference).
129+
130+
One special local variable named `_response` get added after the response received successfully. This local variable is accessible under [_exposable block_](/references/variable-reference#exposable).
122131

123132
### `request` (<small>_`required`_</small>)
124133

125-
`request` is a `_required_` block that defines a http request. It's also a returnable block, meaning it have some scoped variables (namely `return:` sub-block) those represents several sub-part of response received afterward. See [`return:`](#requestreturn) for details.
134+
`request` is a `_required_` block that defines a http request. This holds many other nodes that constructs an http request.
126135

127136
```yaml
128137
request:
@@ -153,9 +162,12 @@ request:
153162

154163
```yaml
155164
request:
165+
url: https://httpbin.org/get
156166
url_params:
157167
sort_by: 'projects'
158168
sort_order: 'DESC'
169+
170+
# https://httpbin.org/get?sort_by=projects&sort_order=DESC
159171
```
160172

161173
### `request.headers`
@@ -180,7 +192,14 @@ request:
180192
request:
181193
auth[basic]:
182194
username: admin
183-
password: 'test1234' # NEVER use this
195+
password: 'test1234'
196+
```
197+
This is same as writing following
198+
199+
```yaml
200+
request:
201+
headers:
202+
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
184203
```
185204

186205
### `request.auth[bearer]`
@@ -280,22 +299,6 @@ request:
280299
...
281300
</catalog>
282301
```
302+
### `expose`
283303

284-
### `request.return`
285-
286-
`request.return` is a sub-block. It's actually not a part of `request` block, meaning it don't define any request parameter unlike others mentioned above. Rather, this block is used to mention what data to return after the response have been received.
287-
288-
Supported values:
289-
290-
- `.version`
291-
- `.code`
292-
- `.reason`
293-
- `.headers`
294-
- `.body`
295-
296-
If not available, or set as null, returns all parts of response.
297-
298-
```yaml
299-
request:
300-
return: ~
301-
```
304+
See docs on [expose node](/references/variable-reference#expose-node)

0 commit comments

Comments
 (0)