|
18 | 18 | Why not use fetch, axios, jQuery, etc..? See [COMPARISON.md](COMPARISON.md).
|
19 | 19 |
|
20 | 20 |
|
| 21 | +## Contents |
| 22 | + |
| 23 | +- [Installation](#installation) |
| 24 | +- [Usage](#usage) |
| 25 | +- [API](#api) |
| 26 | +- [Inspect request config](#inspect-request-config) |
| 27 | +- [Extending](#extending) |
| 28 | +- [Development](#development) |
| 29 | +- [Browser support](#browser-support) |
| 30 | +- [License](#license) (it's MIT) |
| 31 | + |
| 32 | + |
21 | 33 | ## Installation
|
22 | 34 |
|
23 | 35 | Install via npm or yarn:
|
@@ -110,50 +122,6 @@ request
|
110 | 122 | ```
|
111 | 123 |
|
112 | 124 |
|
113 |
| -## Inspect request config |
114 |
| - |
115 |
| -Use the API methods [`toObject`, `config` or `debug`](#toobject) to inspect the configuration of an `SupremeAjaxRequest` instance. |
116 |
| - |
117 |
| -```js |
118 |
| -const req = request.get('https://example.com'); |
119 |
| -console.log(req.toObject().url); |
120 |
| -``` |
121 |
| - |
122 |
| - |
123 |
| -## Extending |
124 |
| - |
125 |
| -Each method of `SupremeAjaxRequest` returns a new instance of `SupremeAjaxRequest`. This is demonstrated in the example below. |
126 |
| - |
127 |
| -The example uses [`toObject`](#toobject) which returns a copy of all configuration of that specific instance at that moment in time. |
128 |
| - |
129 |
| -```js |
130 |
| -const req1 = request |
131 |
| - .get('https://example.com') |
132 |
| - .query({ foo: 'bar' }); |
133 |
| - |
134 |
| -// Extend from previous request |
135 |
| -const req2 = req1.query({ something: 'different' }); |
136 |
| - |
137 |
| -console.log(req2 === req1); // => false |
138 |
| -console.log(req1.toObject().query); // => 'foo=bar' |
139 |
| -console.log(req2.toObject().query); // => 'something=different' |
140 |
| -``` |
141 |
| - |
142 |
| -Practical example of how to create a base request with some defaults and later utilize it for requests: |
143 |
| - |
144 |
| -```js |
145 |
| -const api = request |
146 |
| - .baseUrl('https://example.com/api/v1') |
147 |
| - .headers({ |
148 |
| - 'X-API-KEY': 'secret123' |
149 |
| - }); |
150 |
| - |
151 |
| -// The following requests will use the base URL and headers set above |
152 |
| -api.get('/accounts').send(); |
153 |
| -api.post('/accounts').body(data).send(); |
154 |
| -``` |
155 |
| - |
156 |
| - |
157 | 125 | ## API
|
158 | 126 |
|
159 | 127 | The following methods are available.
|
@@ -533,6 +501,50 @@ const config = req.toObject(); // or req.config() or req.debug()
|
533 | 501 | ```
|
534 | 502 |
|
535 | 503 |
|
| 504 | +## Inspect request config |
| 505 | + |
| 506 | +Use the API methods [`toObject`, `config` or `debug`](#toobject) to inspect the configuration of an `SupremeAjaxRequest` instance. |
| 507 | + |
| 508 | +```js |
| 509 | +const req = request.get('https://example.com'); |
| 510 | +console.log(req.toObject().url); |
| 511 | +``` |
| 512 | + |
| 513 | + |
| 514 | +## Extending |
| 515 | + |
| 516 | +Each method of `SupremeAjaxRequest` returns a new instance of `SupremeAjaxRequest`. This is demonstrated in the example below. |
| 517 | + |
| 518 | +The example uses [`toObject`](#toobject) which returns a copy of all configuration of that specific instance at that moment in time. |
| 519 | + |
| 520 | +```js |
| 521 | +const req1 = request |
| 522 | + .get('https://example.com') |
| 523 | + .query({ foo: 'bar' }); |
| 524 | + |
| 525 | +// Extend from previous request |
| 526 | +const req2 = req1.query({ something: 'different' }); |
| 527 | + |
| 528 | +console.log(req2 === req1); // => false |
| 529 | +console.log(req1.toObject().query); // => 'foo=bar' |
| 530 | +console.log(req2.toObject().query); // => 'something=different' |
| 531 | +``` |
| 532 | + |
| 533 | +Practical example of how to create a base request with some defaults and later utilize it for requests: |
| 534 | + |
| 535 | +```js |
| 536 | +const api = request |
| 537 | + .baseUrl('https://example.com/api/v1') |
| 538 | + .headers({ |
| 539 | + 'X-API-KEY': 'secret123' |
| 540 | + }); |
| 541 | + |
| 542 | +// The following requests will use the base URL and headers set above |
| 543 | +api.get('/accounts').send(); |
| 544 | +api.post('/accounts').body(data).send(); |
| 545 | +``` |
| 546 | + |
| 547 | + |
536 | 548 | ## Development
|
537 | 549 |
|
538 | 550 | ### Tests
|
|
0 commit comments