@d1g1tal/transportr 1.1.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +88 -0
- package/dist/transportr.js +550 -498
- package/dist/transportr.min.js +2 -2
- package/dist/transportr.min.js.map +4 -4
- package/package.json +9 -9
- package/src/transportr.js +107 -58
package/README.md
CHANGED
|
@@ -1,2 +1,90 @@
|
|
|
1
1
|
# transportr
|
|
2
2
|
JavaScript wrapper for Fetch API
|
|
3
|
+
## Installation
|
|
4
|
+
```bash
|
|
5
|
+
npm install @d1g1tal/transportr
|
|
6
|
+
```
|
|
7
|
+
## Usage
|
|
8
|
+
```javascript
|
|
9
|
+
import Transportr from '@d1g1tal/transportr';
|
|
10
|
+
|
|
11
|
+
// Creates default instance configured for JSON requests using UTF-8 encoding.
|
|
12
|
+
const transportr = new Transportr('https://jsonplaceholder.typicode.com', { headers: { [Transportr.RequestHeader.CONTENT_TYPE]: Transportr.MediaType.JSON }, encoding: 'utf-8', });
|
|
13
|
+
|
|
14
|
+
transportr.get('/todos/1')
|
|
15
|
+
.then(json => console.log(json))
|
|
16
|
+
.catch(error => console.error(error.message));
|
|
17
|
+
```
|
|
18
|
+
Or
|
|
19
|
+
|
|
20
|
+
```javascript
|
|
21
|
+
const transportr = new Transportr('https://jsonplaceholder.typicode.com');
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
const todo1 = await transportr.getJson('/todos/1');
|
|
25
|
+
console.log(todo1);
|
|
26
|
+
|
|
27
|
+
const todo2 = await transportr.getJson('/todos/2');
|
|
28
|
+
console.log(todo2);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error(error.message);
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## API
|
|
35
|
+
### Transportr
|
|
36
|
+
#### constructor(options)
|
|
37
|
+
##### options
|
|
38
|
+
Type: `Object`
|
|
39
|
+
|
|
40
|
+
###### options.baseURL
|
|
41
|
+
Type: `String`
|
|
42
|
+
Base URL for all requests.
|
|
43
|
+
|
|
44
|
+
###### options.headers
|
|
45
|
+
Type: `Object`
|
|
46
|
+
Default headers for all requests.
|
|
47
|
+
|
|
48
|
+
###### options.timeout
|
|
49
|
+
Type: `Number`
|
|
50
|
+
Default timeout for all requests.
|
|
51
|
+
|
|
52
|
+
###### options.credentials
|
|
53
|
+
Type: `String`
|
|
54
|
+
Default credentials for all requests.
|
|
55
|
+
|
|
56
|
+
###### options.mode
|
|
57
|
+
Type: `String`
|
|
58
|
+
Default mode for all requests.
|
|
59
|
+
|
|
60
|
+
###### options.cache
|
|
61
|
+
Type: `String`
|
|
62
|
+
Default cache for all requests.
|
|
63
|
+
|
|
64
|
+
###### options.redirect
|
|
65
|
+
Type: `String`
|
|
66
|
+
Default redirect for all requests.
|
|
67
|
+
|
|
68
|
+
###### options.referrer
|
|
69
|
+
Type: `String`
|
|
70
|
+
Default referrer for all requests.
|
|
71
|
+
|
|
72
|
+
###### options.integrity
|
|
73
|
+
Type: `String`
|
|
74
|
+
Default integrity for all requests.
|
|
75
|
+
|
|
76
|
+
###### options.keepalive
|
|
77
|
+
Type: `Boolean`
|
|
78
|
+
Default keepalive for all requests.
|
|
79
|
+
|
|
80
|
+
###### options.signal
|
|
81
|
+
Type: `AbortSignal`
|
|
82
|
+
Default signal for all requests.
|
|
83
|
+
|
|
84
|
+
###### options.encoding
|
|
85
|
+
Type: `String`
|
|
86
|
+
Default encoding for all requests.
|
|
87
|
+
|
|
88
|
+
###### options.body
|
|
89
|
+
Type: `Object|String|FormData|URLSearchParams|Blob|BufferSource|ReadableStream`
|
|
90
|
+
Default body for all requests.
|