Skip to content
This repository has been archived by the owner on Sep 29, 2024. It is now read-only.

Commit

Permalink
feat: Implement DELETE
Browse files Browse the repository at this point in the history
Signed-off-by: AlexNg <[email protected]>
  • Loading branch information
caffeine-addictt committed Aug 1, 2024
1 parent 7a51287 commit a0dcda8
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions client/src/utils/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,14 @@ export interface APIPostRequestParams<T extends APIPayload>
}
export interface APIPutRequestParams<T extends APIPayload>
extends APIPostRequestParams<T> {}
export interface APIDeleteRequestParams extends APIGetRequestParams {}

/** Exposed class */
export interface APIHttpClient {
get<T>(params: APIGetRequestParams): Promise<T>;
post<T, D extends APIPayload>(params: APIPostRequestParams<D>): Promise<T>;
put<T, D extends APIPayload>(params: APIPutRequestParams<D>): Promise<T>;
delete<T>(params: APIDeleteRequestParams): Promise<T>;
}

// Implementation
Expand Down Expand Up @@ -146,7 +149,17 @@ class HTTPClient implements APIHttpClient {
return httpRequestWithCacheHandling<T>(axios.put<T>(url, payload, opts));
};

delete = async <T>({
withCredentials,
options,
...uri
}: APIDeleteRequestParams): Promise<T> => {
const url = resolveUrl(uri);
const opts: AxiosRequestConfig = withCredentials
? addCredentials(withCredentials, options ?? DEFAULT_OPTS)
: (options ?? DEFAULT_OPTS);

return httpRequestWithCacheHandling<T>(axios.delete<T>(url, opts));
};
}

Expand Down

0 comments on commit a0dcda8

Please sign in to comment.