1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
import { apiConfig } from '../../environments/server.config';
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'Auth': 'my_key'
})
};
const httplive = {
headers: new HttpHeaders({
'Access-Control-Allow-Origin': '*'
})
};
const multipartHeader = {
headers: new HttpHeaders({
'enctype': 'multipart/form-data',
'Accept': 'application/json',
'Auth': 'my_key'
})
};
@Injectable({
providedIn: 'root'
})
export class WebService {
constructor(private http: HttpClient) {}
post_data(url: string, data) {
return this.http.post(`${apiConfig + url}`, data, httpOptions).pipe(map((response: any) => response));
}
multipart_post(url: string, data) {
return this.http.post(`${apiConfig + url}`, data, multipartHeader).pipe(map((response: any) => response));
}
get_data(url) {
return this.http.get(`${apiConfig + url}`, httpOptions).pipe(map((response: any) => response));
}
setLocalStorageItem(id: string, data: string) {
localStorage.setItem(id, data);
}
getLocalStorageItem(data: string): string {
return localStorage.getItem(data);
}
removeLocalStorageItem(data) {
localStorage.removeItem(data);
localStorage.clear();
}
get_stored_json(json_file: string) {
return this.http.get("assets/json_data/" + json_file);
}
}