|
13 | 13 | - Understands Content-Type
|
14 | 14 | - Decodes JSON responses by default
|
15 | 15 | - [Works on modern browsers](#browser-support)
|
16 |
| - - No external dependencies |
17 |
| - - See [polyfills](#polyfills) for a list of polyfills you might need for older browsers |
| 16 | + - See [polyfills](#polyfills) for a list of polyfills if you target very old browsers |
| 17 | +- No external dependencies |
| 18 | +- Quite small (<2.5KB minified) |
18 | 19 | - [Fully tested](/test/specs)
|
19 | 20 |
|
| 21 | +Why not use fetch, axios, jQuery, etc..? See [COMPARISON.md](COMPARISON.md). |
| 22 | + |
20 | 23 |
|
21 | 24 | ## Installation
|
22 | 25 |
|
@@ -158,6 +161,29 @@ console.log(req.toObject().url);
|
158 | 161 |
|
159 | 162 | The following methods are available.
|
160 | 163 |
|
| 164 | +- [.get(url)](#get) |
| 165 | +- [.post(url)](#post) |
| 166 | +- [.method(method)](#method) |
| 167 | +- [.url(url)](#url) |
| 168 | +- [.baseUrl(url)](#baseurl) |
| 169 | +- [.query(object | string)](#query) |
| 170 | +- [.headers(object)](#headers) |
| 171 | +- [.amendHeaders(object)](#amendheaders) |
| 172 | +- [.header(key, value)](#header) |
| 173 | +- [.unsetHeader(name)](#unsetheader) |
| 174 | +- [.body(data)](#body) |
| 175 | +- [.json(value)](#json) |
| 176 | +- [.urlencoded(value)](#urlencoded) |
| 177 | +- [.timeout(milliseconds)](#timeout) |
| 178 | +- [.unsetTimeout()](#unsettimeout) |
| 179 | +- [.send([body])](#send) |
| 180 | +- [.sendUrlencoded(data)](#sendurlencoded) |
| 181 | +- [.sendJson(data)](#sendjson) |
| 182 | +- [.setResponseTransformers([])](#setresponsetransformers) |
| 183 | +- [.setAllowedStatusCode(allowed)](#setallowedstatuscode) |
| 184 | +- [.polyfills(polyfills)](#polyfills) |
| 185 | +- [.toObject() / .config() / .debug()](#toobject) |
| 186 | + |
161 | 187 | ### get
|
162 | 188 |
|
163 | 189 | ```js
|
@@ -222,7 +248,7 @@ request.baseUrl('https://example.com/nested/foo').url('accounts') // => https:/
|
222 | 248 | Sets query parameters from an object. Overwrites existing query.
|
223 | 249 |
|
224 | 250 | ```js
|
225 |
| -.query(object) |
| 251 | +.query(object | string) |
226 | 252 | ```
|
227 | 253 |
|
228 | 254 | Where `object` is key-value object of query parameters to set (will be encoded using `URLSearchParams#toString`), or a valid query string.
|
@@ -437,6 +463,15 @@ request.setResponseTransformers([
|
437 | 463 | ]);
|
438 | 464 | ```
|
439 | 465 |
|
| 466 | +Reference to the original array is lost: |
| 467 | + |
| 468 | +```js |
| 469 | +const array = []; |
| 470 | +const req = request.setResponseTransformers(array); |
| 471 | +array.push(someFunction); |
| 472 | +req.toObject().responseTransformers; // not affected by the push, still [] |
| 473 | +``` |
| 474 | + |
440 | 475 | ### setAllowedStatusCode
|
441 | 476 |
|
442 | 477 | By default any 2XX status code resolves the Promise and other status codes will reject it. This can be customized using `setAllowedStatusCode`.
|
|
0 commit comments