diff options
Diffstat (limited to 'web/pw-server/src/lib/utils.ts')
-rw-r--r-- | web/pw-server/src/lib/utils.ts | 37 |
1 files changed, 7 insertions, 30 deletions
diff --git a/web/pw-server/src/lib/utils.ts b/web/pw-server/src/lib/utils.ts index 155d952..ab1faa5 100644 --- a/web/pw-server/src/lib/utils.ts +++ b/web/pw-server/src/lib/utils.ts @@ -1,4 +1,4 @@ -import { get_session_token } from "./auth"; +import { ApiClient, FetchFn } from "./api_client"; export function debounce(func: Function, timeout: number = 300) { let timer: ReturnType<typeof setTimeout>; @@ -10,35 +10,12 @@ export function debounce(func: Function, timeout: number = 300) { }; } -export async function get(url: string, fetch_fn: Function = fetch) { - const headers = { "Content-Type": "application/json" }; - - const token = get_session_token(); - if (token) { - headers["Authorization"] = `Bearer ${token}`; - } - - const response = await fetch_fn(url, { - method: "GET", - headers, - }); - - return JSON.parse(response); +export async function get(url: string, params?: Record<string, string>, fetch_fn: FetchFn = fetch) { + const client = new ApiClient(fetch_fn); + return await client.get(url, params); } -export async function post(url: string, data: any, fetch_fn: Function = fetch) { - const headers = { "Content-Type": "application/json" }; - - const token = get_session_token(); - if (token) { - headers["Authorization"] = `Bearer ${token}`; - } - - const response = await fetch_fn(url, { - method: "POST", - headers, - body: JSON.stringify(data), - }); - - return JSON.parse(response); +export async function post(url: string, data: any, fetch_fn: FetchFn = fetch) { + const client = new ApiClient(fetch_fn); + return await client.post(url, data); } |