Skip to content

Commit

Permalink
feat(utils): add http get method
Browse files Browse the repository at this point in the history
  • Loading branch information
roushou committed Jun 22, 2024
1 parent 02b3889 commit 484f3ff
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/utils/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@ const baseHeaders: HeadersInit = {
"Content-Type": "application/json",
};

export async function get<TResponse>(
url: string,
options?: Omit<RequestInit, "method" | "body">,
): Promise<TResponse> {
const resp = await fetch(url, {
method: "GET",
...options,
headers: {
...baseHeaders,
...options?.headers,
},
});
return (await resp.json()) as TResponse;
}

export async function post<TResponse>(
url: string,
options?: Omit<RequestInit, "method">,
Expand Down

0 comments on commit 484f3ff

Please sign in to comment.