libs/upp-base/src/modules/http.ts
The httpService class provides methods for making HTTP requests and monitoring
internet connectivity across multiple platforms (browser and Cordova). It also
leverages platform-specific plugins for network state management and performs
HTTP requests accordingly, using Angular's HttpClient for web and Ionic's HTTP plugin
for mobile.
This service includes platform-dependent methods for GET, POST, HEAD, and
connectivity checks, managing the different behaviors required by web browsers
and mobile applications.
Additionally, httpService keeps track of the online/offline status and offers an
observable that emits the status whenever it changes. This is useful for components
and other services that need to respond to connectivity changes.
HttpClient.OnDestroy to handle cleanup and avoid memory leaks.Usage in an Angular component to monitor connectivity:constructor(private httpService: httpService) {
this.httpService.OnOnline?.subscribe(status => {
console.log("Online status: ", status);
});
}
this.httpService.get('https://api.example.com/data').subscribe(data => {
console.log(data);
});
Methods |
Accessors |
constructor(platform: platformService, ionic: HTTP, network: Network, angular: HttpClient)
|
||||||||||||||||||||
|
HTTP service constructor.
Parameters :
|
| check |
check()
|
|
Checks the server connection status by making a GET request to a predefined URL.
Returns :
any
Observable that emits connection status. |
| get | ||||||||||||||||||||||||||||||
get(url: string, withCredentials, headers, responseType: HttpResponseTypes | null, timeout: number | null)
|
||||||||||||||||||||||||||||||
|
Performs an HTTP GET request.
Parameters :
Returns :
any
Observable with the HTTP GET response data. |
| head | |||||||||||||||
head(url: string, headers: any)
|
|||||||||||||||
|
Performs an HTTP HEAD request.
Parameters :
Returns :
any
Observable with the HTTP HEAD response data. |
| ngOnDestroy |
ngOnDestroy()
|
|
Cleanup method called on service destruction.
Returns :
void
|
| post | |||||||||||||||||||||||||||||||||||
post(url: string, data: any, headers, responseType: HttpResponseTypes | null, serializer: HttpSerializer | null, timeout: number | null)
|
|||||||||||||||||||||||||||||||||||
|
Performs an HTTP POST request.
Parameters :
Returns :
any
Observable with the HTTP POST response data. |
| IsOnline |
getIsOnline()
|
|
Returns a boolean indicating whether the device is online.
Returns :
boolean
|
| OnOnline |
getOnOnline()
|
|
Observable that emits the internet connection status whenever it changes.
Returns :
Observable<boolean>
|
| headers |
getheaders()
|
|
/ |