@jacraig/request 1.0.1 → 1.0.3
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 +63 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,2 +1,63 @@
|
|
|
1
|
-
# request
|
|
2
|
-
|
|
1
|
+
# @jacraig/request
|
|
2
|
+
|
|
3
|
+
`@jacraig/request` is a powerful yet lightweight library designed to simplify HTTP requests using the native `fetch` API while adding functionality such as caching, retry logic, and timeouts. It aims to provide developers with a convenient and flexible solution for handling HTTP requests in JavaScript and TypeScript applications.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Caching**: Cache responses to improve performance and reduce network requests.
|
|
8
|
+
- **Retry logic**: Automatically retry failed requests with customizable retry options.
|
|
9
|
+
- **Timeouts**: Set timeouts for requests to prevent hanging and improve overall application responsiveness.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
You can install `@jacraig/request` via npm:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @jacraig/request
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
Here's a basic example of how you can use `@jacraig/request` to make a fetch request:
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
|
|
25
|
+
import { Request } from '@jacraig/request';
|
|
26
|
+
|
|
27
|
+
let returnValue = await Request.get('https://jsonplaceholder.somewhere.com/post.json').send();
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
In order to use caching, retry logic, or timeouts, you can use the extra methods on the returned Request object to set options:
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
|
|
35
|
+
import { Request, StorageMode } from '@jacraig/request';
|
|
36
|
+
|
|
37
|
+
let returnValue = await Request.get('https://jsonplaceholder.somewhere.com/post.json')
|
|
38
|
+
.withStorageMode(StorageMode.StorageAndUpdate)
|
|
39
|
+
.withTimeout(5000)
|
|
40
|
+
.withRetryAttempts(3)
|
|
41
|
+
.send();
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
If you prefer to use callbacks instead of promises, you can do so by passing a callback function to the `onSuccess` method:
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
|
|
49
|
+
import { Request } from '@jacraig/request';
|
|
50
|
+
|
|
51
|
+
Request.get('https://jsonplaceholder.somewhere.com/post.json')
|
|
52
|
+
.onSuccess((response) => {
|
|
53
|
+
console.log(response);
|
|
54
|
+
})
|
|
55
|
+
.send();
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Documentation
|
|
60
|
+
For more detailed information on how to use `@jacraig/request`, please refer to the [documentation](https://jacraig.github.io/request/) on GitHub Pages.
|
|
61
|
+
|
|
62
|
+
## License
|
|
63
|
+
@jacraig/request is licensed under the [Apache 2.0 License](https://github.com/JaCraig/request/blob/main/LICENSE)
|
package/package.json
CHANGED