Makes communication with your API a bliss. 😌
- Add
@webfactor/ionic-api-servicevia npm - Add
ApiServiceModule.forRoot()to your Ionic module imports
setBaseUrl(baseUrl: string): voidSets the base URL for all api requests.
getBaseUrl(): stringReturn the base URL for all api requests.
setApiSuffix(suffix: string): stringSet the Api Suffix. Default /api/v1/
getApiSuffix(): stringReturn the api Suffix for all api requests.
getUrl(): stringReturn the URL for all api requests (BaseUrl + Api Suffix).
enableMultiLingual(): voidSets the default values for languageParameter = ?locale= and preferredLanguage = de
setPreferredLanguage(language: string): voidSets preferredLanguage for requestdata output.
get(endpoint: string, params?: any, options?: any): Observable<any>
post(endpoint: string, body: any, options?: any): Observable<any>
put(endpoint: string, body: any, options?: any): Observable<any>
delete(endpoint: string, options?: any): Observable<any>
patch(endpoint: string, body: any, options?: any): Observable<any>Sends requests to the given endpoint.
let headers = new HttpHeaders();
headers = headers.append('Cache-Control', 'no-cache');
this.apiService.get('myEndpoint', {}, { headers })Set Custom Headers
constructor(private apiService: ApiService) {
this.apiService.setBaseUrl('https://webfactormedia.de');
}
getPizza(id: number): void {
this.apiService.get('pizza', { id }).subscribe(response => {
this.pizza = response.data.pizza;
}, err => {
console.log(err);
});
}