Skip to content

Commit 47e5d3c

Browse files
committed
docs: improve readability for http spec
1 parent 5f5e602 commit 47e5d3c

1 file changed

Lines changed: 117 additions & 41 deletions

File tree

docs/references/http-spec.md

Lines changed: 117 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,19 @@ Read details of [*variables*](/docs/references/variables) here.
133133

134134
`request.url` is a required child node to define a valid `http://` or `https://`.
135135

136-
```yml
136+
```yml {2}
137137
request:
138138
url: https://httpbin.org/get
139+
method: OPTIONS
139140
```
140141

141142
### `request.method` (<small>*`required`*</small>)
142143

143144
`request.method` is a required child node to define a valid [HTTP request method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods). All defined methods are `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `OPTIONS`, `HEAD`. It is also possible to use any custom method server recognizes.
144145

145-
```yml
146+
```yml {3}
146147
request:
148+
url: https://httpbin.org/get
147149
method: OPTIONS
148150
```
149151

@@ -153,20 +155,26 @@ request:
153155

154156
E.g. the following block represents `https://httpbin.org/get?sort_by=projects&sort_order=DESC` URL.
155157

156-
```yml
158+
```yml {4-6}
157159
request:
158160
url: https://httpbin.org/get
161+
159162
url_params:
160163
sort_by: "projects"
161164
sort_order: "DESC"
165+
166+
method: OPTIONS
162167
```
163168

164169
### `request.headers`
165170

166171
`request.headers` is a child node to define a set of request headers. It only supports YAML maps, where both keys and values scaler values.
167172

168-
```yml
173+
```yml {5-8}
169174
request:
175+
url: https://httpbin.org/get
176+
method: GET
177+
170178
headers:
171179
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"
172180
Accept-Encoding: "gzip, deflate"
@@ -179,117 +187,171 @@ request:
179187

180188
Here only `username` and `password` is supported. Adding any other value to it is expected to be fruitless.
181189

182-
```yml
190+
```yml {10-12}
183191
request:
192+
url: https://httpbin.org/get
193+
method: GET
194+
195+
headers:
196+
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"
197+
Accept-Encoding: "gzip, deflate"
198+
Accept: "*/*"
199+
184200
auth[basic]:
185201
username: admin
186202
password: "test1234"
187203
```
188204

189-
:::note
190-
191-
Document having `request.auth[bearer]` defined already along with this block will behave unexpectedly.
192-
193-
:::
194-
:::info
205+
::::info
195206

196207
This is same as writing following
197208

198-
```yml
209+
```yml {9}
199210
request:
211+
url: https://httpbin.org/get
212+
method: GET
213+
200214
headers:
215+
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"
216+
Accept-Encoding: "gzip, deflate"
217+
Accept: "*/*"
201218
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
202219
```
220+
:::note
221+
222+
HTTP spec. document having both `request.auth[bearer]` and `request.auth[basic]` on same file will behave unexpectedly.
203223

204224
:::
205225

226+
::::
227+
206228
### `request.auth[bearer]`
207229

208230
`request.auth[bearer]` is a child node to send a [bearer authentication](https://dev.writer.com/docs/authentication) token with the request.
209231

210232
Here only `token` is supported. Adding any other value to it is expected to be fruitless.
211233

212-
```yml
234+
```yml {10-11}
213235
request:
236+
url: https://httpbin.org/get
237+
method: GET
238+
239+
headers:
240+
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"
241+
Accept-Encoding: "gzip, deflate"
242+
Accept: "*/*"
243+
214244
auth[bearer]:
215245
token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
216246
```
217247

218-
:::note
219-
220-
Document having `request.auth[basic]` defined already along with this block will behave unexpectedly.
221-
222-
:::
223-
:::info
248+
::::info
224249

225250
This is same as writing following
226251

227-
```yml
252+
```yml {9}
228253
request:
254+
url: https://httpbin.org/get
255+
method: GET
256+
229257
headers:
258+
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"
259+
Accept-Encoding: "gzip, deflate"
260+
Accept: "*/*"
230261
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
231262
```
263+
:::note
264+
265+
HTTP spec. document having both `request.auth[bearer]` and `request.auth[basic]` on same file will behave unexpectedly.
232266

233267
:::
234268

269+
::::
270+
235271
### `request.body[form]`
236272

237-
`request.body[form]` is a child node to submit a plain html form. This adds `application/x-www-form-urlencoded` form `enctype` in request header.
273+
`request.body[form]` is a child node of `request:` to submit a plain html form. This adds `application/x-www-form-urlencoded` form `enctype` in request header.
238274

239-
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]`.
275+
It only supports key value data, where both key and value should be scaler values. Request will only submit scaler form data, when using `request.body[form]`.
240276

241-
:::info
242-
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.
277+
```yml {9-12}
278+
request:
279+
url: https://httpbin.org/post
280+
method: POST
243281
244-
Given a path to a file will not upload the file.
245-
:::
282+
headers:
283+
Accept-Encoding: "gzip, deflate"
284+
Accept: "*/*"
246285
247-
```yml
248-
request:
249286
body[form]:
250287
"var 1": "var str 1"
251288
var-2: "var str 2"
252289
var_3: file:///home/username/.vimrc
253290
```
291+
:::note
292+
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.
293+
294+
Given a path to a file will not upload the file.
295+
:::
254296

255297
### `request.body[form-data]`
256298

257-
`request.body[form-data]` is a child node to submit a multipart html form. This adds `multipart/form-data` form `enctype` in request header.
299+
`request.body[form-data]` is a child node of `request` to submit a multipart html form. This adds `multipart/form-data` form `enctype` in request header.
258300

259301
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]`.
260302

261-
:::info
262-
263-
You can override `Content-Type` headers if you want, however that will override `Content-Type: multipart/form-data` header which is automatically set.
264-
265-
Given a path to a file will upload the file. 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.
303+
```yml {9-13}
304+
request:
305+
url: https://httpbin.org/post
306+
method: POST
266307
267-
:::
308+
headers:
309+
Accept-Encoding: "gzip, deflate"
310+
Accept: "*/*"
268311
269-
```yml
270-
request:
271312
body[form-data]:
272313
"var 1": 1
273314
var-2: "var str 2"
274315
var_3: file:///home/username/.vimrc
275316
var4: file:///home/username/Documents/CID-25601.IpPhone.rtf
276317
```
318+
:::note
319+
320+
You can override `Content-Type` headers if you want, however that will override `Content-Type: multipart/form-data` header which is automatically set.
321+
322+
Given a path to a file will upload the file. 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.
323+
324+
:::
277325

278326
### `request.body[text]`
279327

280328
`request.body[text]` is a child node to submit a plain text. This adds `text/plain` form `enctype`in request header.
281329

282330
It only supports string. Multiple line of string is also supported.
283331

284-
```yml
332+
```yml {9}
285333
request:
334+
url: https://httpbin.org/post
335+
method: POST
336+
337+
headers:
338+
Accept-Encoding: "gzip, deflate"
339+
Accept: "*/*"
340+
286341
body[text]: Some plain text here
287342
```
288343

289344
or can set multiline text. i.e:
290345

291-
```yml
346+
```yml {9-11}
292347
request:
348+
url: https://httpbin.org/post
349+
method: POST
350+
351+
headers:
352+
Accept-Encoding: "gzip, deflate"
353+
Accept: "*/*"
354+
293355
body[text]: |
294356
Some plain text here
295357
Other line here
@@ -301,8 +363,15 @@ request:
301363

302364
It supports key value data, where key should be scaler, and value can be of YAML collection type those are convertible to json.
303365

304-
```yml
366+
```yml {9-14}
305367
request:
368+
url: https://httpbin.org/put
369+
method: PUT
370+
371+
headers:
372+
Accept-Encoding: "gzip, deflate"
373+
Accept: "*/*"
374+
306375
body[json]:
307376
user_id: 32
308377
roll_no: 1
@@ -317,8 +386,15 @@ request:
317386

318387
It only supports string data.
319388

320-
```yml
389+
```yml {9-22}
321390
request:
391+
url: https://httpbin.org/put
392+
method: PUT
393+
394+
headers:
395+
Accept-Encoding: "gzip, deflate"
396+
Accept: "*/*"
397+
322398
body[xml]: |
323399
<?xml version="1.0"?>
324400
<catalog>

0 commit comments

Comments
 (0)