http-request-manager 4.1.2 → 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,29 +2,57 @@
2
2
 
3
3
  This library has 4 main services that simplify http requests, http request state and local storage states.
4
4
 
5
- 1) [HttpRequestManager](./README/REQUEST_MANAGER_README.md) (service): This service provides http requests (CRUD operations)
5
+ Here is an example:
6
6
 
7
- 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
+ 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`
8
9
 
9
- 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.
10
+ Setup the options
10
11
 
11
- 4) [DatabaseManagerService](./README/DATABASE_MANAGER_README.md) (beta): This extends the `Http-Request-State-Manager` with persistent storage using `DexieJS`, a minimalistic wrapper for IndexedDB (local browser DB). This service defines a table linked to HTTP requests, storing the retrieved data locally. Upon subsequent requests, the `Http-Request-State-Manager` checks the local database first; if the data is absent, it proceeds with the HTTP request. This approach reduces redundant HTTP requests, enhances application responsiveness, and enables offline functionality without requiring an internet connection.
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'
12
24
 
13
- 5) [Interceptors](./README/INTERCEPTORS_README.md): General interceptors that may be applied to the providers for requests.
14
- This includes:
15
-
16
- - credentials - adds the { credentials: true } options for secure cookies to be persistent
25
+ ```ts
26
+ this.data$ = this.httpManagerService.getRequest<ClientInfo[]>(reqParams, [userId, 'users', { sortBy: 'asc' }])
27
+ ```
17
28
 
18
- - proxy-debugger for debugging api requests
29
+ This returns an Observable which you then can implement it in your template as
19
30
 
20
- - request-error for catching all requests the error with 400-500 status and presents a toast-message (snackbar) with the error
31
+ `{{ (data$ | async) | json }}`
21
32
 
22
- - request-header provides a few properties that are added to all requests
23
- - 'Content-Type': 'application/json', // BE header for json type requests
24
- - 'Accept-Language': this.language || 'en-CA', //language localization
25
- - 'Current-Date': this.currentDate //todays date
33
+ ## Overview
26
34
 
35
+ 1) [HttpRequestManager](./README/REQUEST_MANAGER_README.md) (service): This service provides http requests (CRUD operations)
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.
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.
38
+ 4) [DatabaseManagerService](./README/DATABASE_MANAGER_README.md) (beta): This extends the `Http-Request-State-Manager` with persistent storage using `DexieJS`, a minimalistic wrapper for IndexedDB (local browser DB). This service defines a table linked to HTTP requests, storing the retrieved data locally. Upon subsequent requests, the `Http-Request-State-Manager` checks the local database first; if the data is absent, it proceeds with the HTTP request. This approach reduces redundant HTTP requests, enhances application responsiveness, and enables offline functionality without requiring an internet connection.
39
+ 5) [Interceptors](./README/INTERCEPTORS_README.md): General interceptors that may be applied to the providers for requests.
40
+ This includes:
41
+
42
+ - credentials - adds the { credentials: true } options for secure cookies to be persistent
43
+ - proxy-debugger for debugging api requests
44
+ - request-error for catching all requests the error with 400-500 status and presents a toast-message (snackbar) with the error
45
+ - request-header provides a few properties that are added to all requests
46
+
47
+ - 'Content-Type': 'application/json', // BE header for json type requests
48
+ - 'Accept-Language': this.language || 'en-CA', //language localization
49
+ - 'Current-Date': this.currentDate //todays date
27
50
  6) [Proxy-Config](./README/INTERCEPTORS_README.md) Support: This allows for proxies to be used when requests are made that are defined.
51
+ 7) Demos available for all the above that demonstrate all functionality
52
+
53
+ - import `HttpRequestManagerModule`
54
+ - add the selector `<app-http-request-services-demo></app-http-request-services-demo>` to a template
55
+ - explore the many options - Top right menus toggles between the above services
28
56
 
29
57
  ## HttpServiceManager, HttpRequestStateManager and DatabaseManagerService Features:
30
58
 
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "http-request-manager",
3
- "version": "4.1.2",
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