Skip to content

Commit c50e466

Browse files
committed
Http specification reference
- add block documentation
1 parent e55fb99 commit c50e466

1 file changed

Lines changed: 188 additions & 1 deletion

File tree

docs/05-References/051-http-reference.md

Lines changed: 188 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ title: Http specification reference
99

1010
Let’s get introduced to the Http specification format. 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.
13+
14+
> [TBD] It's also an exposable document meaning, you can expose local variables to whatever other spec. document it's called from.
15+
16+
### Reference as example
17+
1218
```yaml
13-
---
1419
request:
1520
# valid URL
1621
url: https://httpbin.org/get
@@ -105,3 +110,185 @@ request:
105110
# if not available, or set as null, returns all parts of response
106111
return: ~
107112
```
113+
114+
---
115+
116+
### `request` (<small>_`required`_</small>)
117+
118+
`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.
119+
120+
```yaml
121+
request:
122+
...
123+
```
124+
125+
### `request.url` (<small>_`required`_</small>)
126+
127+
`request.url` is a `_required_` sub-block, that is used to define a valid `http://` or `https://` for now.
128+
129+
```yaml
130+
request:
131+
url: https://httpbin.org/get
132+
```
133+
134+
### `request.method` (<small>_`required`_</small>)
135+
136+
`request.method` is a `_required_` sub-block, that is used to define a valid [HTTP request method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods). Acceptable values are `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `OPTIONS`, `HEAD`.
137+
138+
```yaml
139+
request:
140+
method: OPTIONS
141+
```
142+
143+
### `request.url_params`
144+
145+
`request.url_params` is a sub-block, that is used to define a set of url parameters or query string. It only supports key value data, where key should be scaler values.
146+
147+
```yaml
148+
request:
149+
url_params:
150+
sort_by: 'projects'
151+
sort_order: 'DESC'
152+
```
153+
154+
### `request.headers`
155+
156+
`request.headers` is a sub-block, that is used to define a set of request headers. It only supports key value data, where both key and value should be scaler values.
157+
158+
```yaml
159+
request:
160+
headers:
161+
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'
162+
Accept-Encoding: 'gzip, deflate'
163+
Accept: '*/*'
164+
```
165+
166+
### `request.auth[basic]`
167+
168+
`request.auth[basic]` is a sub-block, that is used to send basic authentication informaions with the request. It's to be used for [basic authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication#basic_authentication_scheme). It only supports key value data, where both key and value should be scaler values. only `username` and `password` is supported. Adding any other value to it is expected to be fruitless.
169+
170+
> If a document already have `request.auth[bearer]` defined along with this block, `chk` will behave unexpectedly.
171+
172+
```yaml
173+
request:
174+
auth[basic]:
175+
username: admin
176+
password: 'test1234' # NEVER use this
177+
```
178+
179+
### `request.auth[bearer]`
180+
181+
`request.auth[bearer]` is a sub-block, that is used to send a bearer token with the request. It's to be used for [bearer authentication](https://dev.writer.com/docs/authentication). It only supports key value data, where both key and value should be scaler values. only `token` is supported. Adding any other value to it is expected to be fruitless.
182+
183+
> If a document already have `request.auth[basic]` defined along with this block, `chk` will behave unexpectedly.
184+
185+
```yaml
186+
request:
187+
auth[bearer]:
188+
token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
189+
```
190+
191+
### `request.body[form]`
192+
193+
`request.body[form]` is a sub-block, that is used to submit a html form. More accurately send `application/x-www-form-urlencoded` form `enctype`. It only supports key value data, where both key and value should be scaler values. Request will only submit scaler form data while using `request.body[form]`.
194+
195+
You can override `Content-Type` headers if you want, however that will override `Content-Type: application/x-www-form-urlencoded` header which is automatically set.
196+
197+
```yaml
198+
request:
199+
body[form]:
200+
'var 1': 'var str 1'
201+
var-2: 'var str 2'
202+
var_3: file:///home/username/.vimrc # note: this will just pass filepath as value
203+
```
204+
205+
### `request.body[form-data]`
206+
207+
`request.body[form-data]` is a sub-block, that is used to submit a multipart html form. More accurately send `multipart/form-data` form `enctype`. It only supports key value data, where both key and value should be scaler values. Request will submit multipart form data while using `request.body[form-data]`, therefore can be used to upload binary content or file.
208+
209+
You can override `Content-Type` headers if you want, however that will override `Content-Type: multipart/form-data` header which is automatically set.
210+
211+
Note, that you can upload files in this way. Please follow [this section on wikipedia](https://en.wikipedia.org/wiki/File_URI_scheme#Examples) on `file://` to set path on different OS platform.
212+
213+
```yaml
214+
request:
215+
body[form-data]:
216+
'var 1': 1
217+
var-2: 'var str 2'
218+
var_3: file:///home/username/.vimrc
219+
var4: file:///home/username/Documents/CID-25601.IpPhone.rtf
220+
```
221+
222+
### `request.body[text]`
223+
224+
`request.body[text]` is a sub-block, that is used to submit a plain text form. More accurately send `text/plain` form `enctype`. It only supports string. Multiple line of string is also supported.
225+
226+
227+
```yaml
228+
request:
229+
body[text]: Some plain text here
230+
```
231+
232+
or can set multiline text. i.e:
233+
234+
```yaml
235+
request:
236+
body[text]: |
237+
Some plain text here
238+
Other line here
239+
```
240+
241+
### `request.body[json]`
242+
243+
`request.body[json]` is a sub-block, that is used to submit a raw json data with the request. This automatically sets `Content-Type: application/json` request header. It supports key value data, where key should be scaler, and value can be of object type those are convertible to json.
244+
245+
```yaml
246+
request:
247+
body[json]:
248+
user_id: 32
249+
roll_no: 1
250+
person:
251+
class: 2
252+
name: 'Student name'
253+
```
254+
255+
### `request.body[xml]`
256+
257+
`request.body[xml]` is a sub-block, that is used to submit a raw xml data with the request. This automatically sets `Content-Type: application/xml` request header. It only supports string data. However, you can use variables to write dynamic data to XML.
258+
259+
```yaml
260+
request:
261+
body[xml]: |
262+
<?xml version="1.0"?>
263+
<catalog>
264+
<book id="bk101">
265+
<author>Gambardella, Matthew</author>
266+
<title>XML Developer's Guide</title>
267+
<genre>Computer</genre>
268+
<price>44.95</price>
269+
<publish_date>2000-10-01</publish_date>
270+
<description>An in-depth look at creating applications
271+
with XML.</description>
272+
</book>
273+
...
274+
</catalog>
275+
```
276+
277+
### `request.return`
278+
279+
`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.
280+
281+
Supported values:
282+
283+
- `.version`
284+
- `.code`
285+
- `.reason`
286+
- `.headers`
287+
- `.body`
288+
289+
If not available, or set as null, returns all parts of response.
290+
291+
```yaml
292+
request:
293+
return: ~
294+
```

0 commit comments

Comments
 (0)