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
Copy file name to clipboardExpand all lines: docs/04-Examples/041-http-examples.md
+45-15Lines changed: 45 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,17 +3,15 @@ title: Http spec. examples
3
3
---
4
4
5
5
:::note
6
-
7
6
- This page should be use as reference for specification files.
8
7
- This page is subject to change. It is requested to check this page frequently.
9
-
10
8
:::
11
9
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
13
11
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.
15
13
16
-
### Minimal request
14
+
### Minimal request with HTTP GET method
17
15
18
16
```yaml
19
17
---
@@ -27,8 +25,9 @@ request:
27
25
28
26
```yaml
29
27
---
30
-
# put variables on the path
28
+
version: default:http:0.7.2
31
29
request:
30
+
# put variables on the path for query string
32
31
url: https://example.org/api/path?foo=bar&two=2
33
32
method: GET
34
33
```
@@ -37,10 +36,12 @@ or you can also do like:
37
36
38
37
```yaml
39
38
---
40
-
# put variables as url_params entry
39
+
version: default:http:0.7.2
41
40
request:
42
41
url: https://example.org/api/path
43
42
method: GET
43
+
44
+
# put variables as url_params entry for query string
44
45
url_params:
45
46
foo: bar
46
47
two: 2
@@ -50,6 +51,8 @@ request:
50
51
51
52
```yaml
52
53
---
54
+
version: default:http:0.7.2
55
+
53
56
request:
54
57
url: https://example.org/api/resource/action
55
58
method: GET
@@ -67,6 +70,8 @@ request:
67
70
68
71
```yaml
69
72
---
73
+
version: default:http:0.7.2
74
+
70
75
request:
71
76
url: https://example.org/api/resource/id
72
77
method: GET
@@ -86,6 +91,8 @@ request:
86
91
87
92
```yaml
88
93
---
94
+
version: default:http:0.7.2
95
+
89
96
request:
90
97
url: https://example.org/api/resource/id
91
98
method: GET
@@ -102,6 +109,8 @@ request:
102
109
103
110
```yaml
104
111
---
112
+
version: default:http:0.7.2
113
+
105
114
request:
106
115
url: https://example.org/api/resource/action
107
116
method: POST
@@ -120,6 +129,8 @@ request:
120
129
121
130
```yaml
122
131
---
132
+
version: default:http:0.7.2
133
+
123
134
request:
124
135
url: https://example.org/api/resource/action
125
136
method: POST
@@ -136,17 +147,22 @@ request:
136
147
137
148
### Request with form
138
149
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.
140
155
141
156
```yaml
142
157
---
158
+
version: default:http:0.7.2
159
+
143
160
request:
144
161
url: https://example.org/api/resource/action
145
162
method: POST
146
163
147
164
headers:
148
165
Accept-Encoding: gzip, deflate
149
-
Content-Type: application/json
150
166
151
167
auth[bearer]:
152
168
token: eyJhbGciOiJIU...4fwpMeJf36POk6yJV_adQssw5c
@@ -156,22 +172,31 @@ request:
156
172
roll_no: 1,
157
173
class: 2,
158
174
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
160
179
```
161
180
162
181
### Request with file upload
163
182
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
+
165
189
166
190
```yaml
167
191
---
192
+
version: default:http:0.7.2
193
+
168
194
request:
169
195
url: https://example.org/api/resource/id
170
196
method: PUT
171
197
172
198
headers:
173
199
Accept-Encoding: gzip, deflate
174
-
Content-Type: application/json
175
200
176
201
auth[bearer]:
177
202
token: eyJhbGciOiJIU...4fwpMeJf36POk6yJV_adQssw5c
@@ -181,23 +206,28 @@ request:
181
206
roll_no: 1,
182
207
class: 2,
183
208
name: 'Student name'
184
-
photo: file:///home/username/student-photo-01.png # note: this will actually upload the file
0 commit comments