Skip to content

Commit b7c44c5

Browse files
committed
Add more details to examples
- add version string - details instructions - remove unnecessary headers
1 parent d9d8ebe commit b7c44c5

1 file changed

Lines changed: 45 additions & 15 deletions

File tree

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

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@ title: Http spec. examples
33
---
44

55
:::note
6-
76
- This page should be use as reference for specification files.
87
- This page is subject to change. It is requested to check this page frequently.
9-
108
:::
119

12-
Case-wise more example can be found in `tests/resources/storage/sample_config` directory of https://github.com/chkware/cli repository
10+
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
1311

14-
Following are the examples with HTTP GET method. Although all these example are still valid for POST, PUT, PATCH, DELETE, OPTIONS, HEAD method as well.
12+
Following are the examples with HTTP _GET_ method. Although all these example are still valid for _POST_, _PUT_, _PATCH_, _DELETE_, _OPTIONS_, _HEAD_ method as well.
1513

16-
### Minimal request
14+
### Minimal request with HTTP GET method
1715

1816
```yaml
1917
---
@@ -27,8 +25,9 @@ request:
2725
2826
```yaml
2927
---
30-
# put variables on the path
28+
version: default:http:0.7.2
3129
request:
30+
# put variables on the path for query string
3231
url: https://example.org/api/path?foo=bar&two=2
3332
method: GET
3433
```
@@ -37,10 +36,12 @@ or you can also do like:
3736
3837
```yaml
3938
---
40-
# put variables as url_params entry
39+
version: default:http:0.7.2
4140
request:
4241
url: https://example.org/api/path
4342
method: GET
43+
44+
# put variables as url_params entry for query string
4445
url_params:
4546
foo: bar
4647
two: 2
@@ -50,6 +51,8 @@ request:
5051
5152
```yaml
5253
---
54+
version: default:http:0.7.2
55+
5356
request:
5457
url: https://example.org/api/resource/action
5558
method: GET
@@ -67,6 +70,8 @@ request:
6770
6871
```yaml
6972
---
73+
version: default:http:0.7.2
74+
7075
request:
7176
url: https://example.org/api/resource/id
7277
method: GET
@@ -86,6 +91,8 @@ request:
8691

8792
```yaml
8893
---
94+
version: default:http:0.7.2
95+
8996
request:
9097
url: https://example.org/api/resource/id
9198
method: GET
@@ -102,6 +109,8 @@ request:
102109

103110
```yaml
104111
---
112+
version: default:http:0.7.2
113+
105114
request:
106115
url: https://example.org/api/resource/action
107116
method: POST
@@ -120,6 +129,8 @@ request:
120129

121130
```yaml
122131
---
132+
version: default:http:0.7.2
133+
123134
request:
124135
url: https://example.org/api/resource/action
125136
method: POST
@@ -136,17 +147,22 @@ request:
136147

137148
### Request with form
138149

139-
Following example will submit a plain html form POST with encoding type `application/x-www-form-urlencoded`
150+
Following example will submit a form with POST method. You do not need to set any special header for this.
151+
152+
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.
153+
154+
Note, that you can not upload files in this way. See **Request with file upload** section for that purpose.
140155

141156
```yaml
142157
---
158+
version: default:http:0.7.2
159+
143160
request:
144161
url: https://example.org/api/resource/action
145162
method: POST
146163
147164
headers:
148165
Accept-Encoding: gzip, deflate
149-
Content-Type: application/json
150166
151167
auth[bearer]:
152168
token: eyJhbGciOiJIU...4fwpMeJf36POk6yJV_adQssw5c
@@ -156,22 +172,31 @@ request:
156172
roll_no: 1,
157173
class: 2,
158174
name: 'Student name'
159-
photo: file:///home/username/student-photo-01.png # note: this will just pass filepath as string, not the actual file
175+
176+
# note: this will just set photo with file path as string,
177+
# but will not upload the actual file
178+
photo: file:///home/username/student-photo-01.png
160179
```
161180

162181
### Request with file upload
163182

164-
Following example will submit a plain html form POST with encoding type `multipart/form-data`
183+
Following example will submit a form with binary image data in POST method. You do not need to set any special header for this.
184+
185+
You can override `Content-Type` headers if you want, however that will override `Content-Type: multipart/form-data` header which is automatically set.
186+
187+
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.
188+
165189

166190
```yaml
167191
---
192+
version: default:http:0.7.2
193+
168194
request:
169195
url: https://example.org/api/resource/id
170196
method: PUT
171197
172198
headers:
173199
Accept-Encoding: gzip, deflate
174-
Content-Type: application/json
175200
176201
auth[bearer]:
177202
token: eyJhbGciOiJIU...4fwpMeJf36POk6yJV_adQssw5c
@@ -181,23 +206,28 @@ request:
181206
roll_no: 1,
182207
class: 2,
183208
name: 'Student name'
184-
photo: file:///home/username/student-photo-01.png # note: this will actually upload the file
209+
210+
# note: this will actually upload the file
211+
photo: file:///home/username/student-photo-01.png
185212
cover_photo: file:///home/username/student-cvphoto-01.png
186213
```
187214

188215
### Request with XML in body
189216

190-
Following example will submit a plain html form POST with encoding type `multipart/form-data`
217+
Following example will POST a plain xml content.
218+
219+
You can override `Content-Type` headers if you want, however that will override ``Content-Type: application/xml` header which is automatically set.
191220

192221
```yaml
193222
---
223+
version: default:http:0.7.2
224+
194225
request:
195226
url: https://example.org/api/resource/action
196227
method: POST
197228
198229
headers:
199230
Accept-Encoding: gzip, deflate
200-
Content-Type: application/xml
201231
202232
body[xml]: |
203233
<?xml version="1.0"?>

0 commit comments

Comments
 (0)