http-request-manager 4.1.3 → 4.1.4
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
CHANGED
|
@@ -2,6 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
This library has 4 main services that simplify http requests, http request state and local storage states.
|
|
4
4
|
|
|
5
|
+
Here is an example:
|
|
6
|
+
|
|
7
|
+
In this example we want to GET data from this URL with the following query params:
|
|
8
|
+
`http://localhost:4200/assets/as/auth/1234/users?sortBy=asc`
|
|
9
|
+
|
|
10
|
+
Setup the options
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
const reqParams = ApiRequest.adapt({
|
|
14
|
+
server: 'http://localhost:4200/assets', // baseUrl
|
|
15
|
+
path: ['as', 'auth'], // additional paths you want to add
|
|
16
|
+
polling: 30, //make same request every 30s
|
|
17
|
+
retry: { times: 3, delay: 3 }, // retry 3 times spacing next the retry by 3 seconds
|
|
18
|
+
displayError: true // display toast if error occurs
|
|
19
|
+
adapter: ClientInfo.adpat // Client Model/Adapter class
|
|
20
|
+
})
|
|
21
|
+
```
|
|
22
|
+
Now we use the base configs made above and when we make the request we want to add an `userId` which contains `1234` and path `'/users'`
|
|
23
|
+
We also want to add query params to the request `{ sortBy: 'asc'}` which will be 'sortBy=asc'
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
this.data$ = this.httpManagerService.getRequest<ClientInfo[]>(reqParams, [userId, 'users', { sortBy: 'asc' }])
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
This returns an Observable which you then can implement it in your template as
|
|
30
|
+
|
|
31
|
+
`{{ (data$ | async) | json }}`
|
|
32
|
+
|
|
33
|
+
## Overview
|
|
34
|
+
|
|
5
35
|
1) [HttpRequestManager](./README/REQUEST_MANAGER_README.md) (service): This service provides http requests (CRUD operations)
|
|
6
36
|
2) [HttpRequestStateManager](./README/REQUEST_STATE_MANAGER_README.md) (service): This service manages HTTP requests by maintaining state, eliminating the need to construct separate API calls for POST, PUT, and DELETE operations. It uses a GET request to retrieve an array of items and applies standard REST rules to update the state. When the state changes—either by adding a new record or modifying an existing one—the service automatically performs the appropriate POST, PUT, or DELETE requests without requiring explicit API calls.
|
|
7
37
|
3) [LocalStorageManager](./README/LOCAL_STORAGE_MANAGER_README.md) (service): Enables the storage of data object structures in either localStorage or sessionStorage, maintaining an updated state to reflect storage changes. This approach eliminates the need to manually serialize and deserialize data structures using JSON.stringify and JSON.parse, streamlining data handling. By synchronizing state with storage updates, the service ensures immediate availability of the current state without relying on timers, thereby preventing potential side effects associated with delayed storage operations.
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "http-request-manager",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.4",
|
|
4
4
|
"description": "This library has 4 main services that simplify http requests, http request state and local storage states.",
|
|
5
5
|
"author": "Michele Bonifacio",
|
|
6
6
|
"company": "wavecoders.ca",
|
|
Binary file
|