You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
11
11
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
+
12
18
```yaml
13
-
---
14
19
request:
15
20
# valid URL
16
21
url: https://httpbin.org/get
@@ -105,3 +110,185 @@ request:
105
110
# if not available, or set as null, returns all parts of response
106
111
return: ~
107
112
```
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.
`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.
`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.
`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.
0 commit comments