File: /var/www/vhost/disk-apps/pwa.sports-crowd.com/src/app/services/api-main.service.ts
import { HttpClient, HttpParams, HttpHeaders } from "@angular/common/http";
import { Injectable } from "@angular/core";
import { environment } from '../../environments/environment';
@Injectable({
providedIn: "root",
})
export class ApiMainService {
url = environment.apiUrl;
constructor(public http: HttpClient) { }
get(endpoint: string, params?: any, reqOpts?: any) {
if (!reqOpts) {
reqOpts = {
params: new HttpParams(),
};
}
// Support easy query params for GET requests
if (params) {
reqOpts.params = new HttpParams();
for (let k in params) {
reqOpts.params = reqOpts.params.set(k, params[k]);
}
}
return this.http.get(this.url + "/" + endpoint, reqOpts);
}
getFree(endpoint: string, params?: any, reqOpts?: any) {
if (!reqOpts) {
reqOpts = {
params: new HttpParams(),
};
}
// Support easy query params for GET requests
if (params) {
reqOpts.params = new HttpParams();
for (let k in params) {
reqOpts.params = reqOpts.params.set(k, params[k]);
}
}
return this.http.get(this.url + "/" + endpoint, reqOpts);
}
post(endpoint: string, body: any, reqOpts?: any) {
return this.http.post(this.url + "/" + endpoint, body, reqOpts);
}
postFree(endpoint: string, body: any, reqOpts?: any) {
return this.http.post(this.url + "/" + endpoint, body, reqOpts);
}
put(endpoint: string, body: any, token: any, reqOpts?: any) {
let headers = new HttpHeaders({
Authorization: "Bearer " + token,
});
return this.http.put(this.url + "/" + endpoint, body, { headers });
}
putFree(endpoint: string, body: any, reqOpts?: any) {
return this.http.put(this.url + "/" + endpoint, body, reqOpts);
}
delete(endpoint: string, reqOpts?: any) {
return this.http.delete(this.url + "/" + endpoint, reqOpts);
}
patch(endpoint: string, body: any, reqOpts?: any) {
return this.http.patch(this.url + "/" + endpoint, body, reqOpts);
}
}