18 lines
500 B
JavaScript
18 lines
500 B
JavaScript
//#region src/client/utils/http.ts
|
|
const http = {
|
|
get: async (url, query) => {
|
|
const _url = new URL(url);
|
|
if (query) for (const [key, value] of Object.entries(query)) _url.searchParams.append(key, value);
|
|
return await (await fetch(_url.toString())).json();
|
|
},
|
|
post: async (url, data) => {
|
|
return await (await fetch(url, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: data ? JSON.stringify(data) : void 0
|
|
})).json();
|
|
}
|
|
};
|
|
|
|
//#endregion
|
|
export { http }; |