Commit 7fcc869
committed
fix: simplify http client
The conventions in the Fetch API is that you make a request, then do something
with the response:
```javascript
const response = await fetch('...')
const data = await response.json()
```
It doesn't do things like:
```javascript
const data = await fetch.json('...') // what method would this use?
```
This PR brings our API more inline with Fetch so where we used to do:
```javascript
for await (const datum of http.ndjson('...')) { // what method does this use?
}
```
We now do the more idiomatic:
```javascript
const response = await http.post('...')
for await (const datum of response.ndjson()) {
}
```
It also removes the `.iterator` and `.stream` methods as they do not
follow the Fetch pattern either though they can be added to the response
object if they are useful.
BREAKING CHANGE:
- The `.ndjson`, `.stream` and `.iterator` methods have been removed
- An `.ndjson` async generator function has been added to the response which
does the same thing the `.ndjson` instance method used to
Old:
```javascript
for await (const datum of http.ndjson('http://...')) {
}
```
New:
```javascript
const response = await http.post('http://...')
for await (const datum of response.ndjson()) {
}
```1 parent 03e1dd3 commit 7fcc869
2 files changed
+27
-47
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
139 | 155 | | |
140 | 156 | | |
141 | 157 | | |
| |||
183 | 199 | | |
184 | 200 | | |
185 | 201 | | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | 202 | | |
233 | 203 | | |
234 | 204 | | |
| |||
309 | 279 | | |
310 | 280 | | |
311 | 281 | | |
312 | | - | |
313 | 282 | | |
314 | 283 | | |
315 | 284 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
30 | 41 | | |
31 | 42 | | |
32 | 43 | | |
| |||
0 commit comments