Skip to content

Commit c2876bc

Browse files
committed
Further reorganize README
1 parent 7da1114 commit c2876bc

File tree

1 file changed

+56
-44
lines changed

1 file changed

+56
-44
lines changed

README.md

+56-44
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@
1818
Why not use fetch, axios, jQuery, etc..? See [COMPARISON.md](COMPARISON.md).
1919

2020

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+
2133
## Installation
2234

2335
Install via npm or yarn:
@@ -110,50 +122,6 @@ request
110122
```
111123

112124

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-
157125
## API
158126

159127
The following methods are available.
@@ -533,6 +501,50 @@ const config = req.toObject(); // or req.config() or req.debug()
533501
```
534502

535503

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+
536548
## Development
537549

538550
### Tests

0 commit comments

Comments
 (0)