|
|
@@ -20,9 +20,14 @@ class ApiRequestService {
|
|
|
*
|
|
|
* @param url
|
|
|
* @param query
|
|
|
+ * @param headers
|
|
|
*/
|
|
|
- public async get(url: string, query: AssociativeArray | null = null) {
|
|
|
- return await this.request(HTTP_METHOD.GET, url, null, query)
|
|
|
+ public async get(
|
|
|
+ url: string,
|
|
|
+ query: AssociativeArray | null = null,
|
|
|
+ headers: AssociativeArray | null = null,
|
|
|
+ ) {
|
|
|
+ return await this.request(HTTP_METHOD.GET, url, null, query, headers)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -31,13 +36,15 @@ class ApiRequestService {
|
|
|
* @param url
|
|
|
* @param body
|
|
|
* @param query
|
|
|
+ * @param headers
|
|
|
*/
|
|
|
public async post(
|
|
|
url: string,
|
|
|
body: string | AnyJson | null = null,
|
|
|
query: AssociativeArray | null = null,
|
|
|
+ headers: AssociativeArray | null = null,
|
|
|
) {
|
|
|
- return await this.request(HTTP_METHOD.POST, url, body, query)
|
|
|
+ return await this.request(HTTP_METHOD.POST, url, body, query, headers)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -46,13 +53,15 @@ class ApiRequestService {
|
|
|
* @param url
|
|
|
* @param body
|
|
|
* @param query
|
|
|
+ * @param headers
|
|
|
*/
|
|
|
public async put(
|
|
|
url: string,
|
|
|
body: string | AnyJson | null = null,
|
|
|
query: AssociativeArray | null = null,
|
|
|
+ headers: AssociativeArray | null = null,
|
|
|
) {
|
|
|
- return await this.request(HTTP_METHOD.PUT, url, body, query)
|
|
|
+ return await this.request(HTTP_METHOD.PUT, url, body, query, headers)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -60,9 +69,14 @@ class ApiRequestService {
|
|
|
*
|
|
|
* @param url
|
|
|
* @param query
|
|
|
+ * @param headers
|
|
|
*/
|
|
|
- public async delete(url: string, query: AssociativeArray | null = null) {
|
|
|
- return await this.request(HTTP_METHOD.DELETE, url, null, query)
|
|
|
+ public async delete(
|
|
|
+ url: string,
|
|
|
+ query: AssociativeArray | null = null,
|
|
|
+ headers: AssociativeArray | null = null,
|
|
|
+ ) {
|
|
|
+ return await this.request(HTTP_METHOD.DELETE, url, null, query, headers)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -72,6 +86,7 @@ class ApiRequestService {
|
|
|
* @param url
|
|
|
* @param body
|
|
|
* @param query
|
|
|
+ * @param headers
|
|
|
* @protected
|
|
|
*/
|
|
|
protected async request(
|
|
|
@@ -79,6 +94,7 @@ class ApiRequestService {
|
|
|
url: string,
|
|
|
body: string | AnyJson | null = null,
|
|
|
query: AssociativeArray | null = null,
|
|
|
+ headers: AssociativeArray | null = null,
|
|
|
): Promise<Response> {
|
|
|
const config: FetchOptions = { method }
|
|
|
if (query) {
|
|
|
@@ -87,6 +103,9 @@ class ApiRequestService {
|
|
|
if (method === HTTP_METHOD.POST || method === HTTP_METHOD.PUT) {
|
|
|
config.body = body
|
|
|
}
|
|
|
+ if (headers) {
|
|
|
+ config.headers = headers
|
|
|
+ }
|
|
|
|
|
|
// @ts-expect-error TODO: solve the type mismatch
|
|
|
return await this.fetch(url, config)
|