mirror of
https://github.com/luckfox-eng29/kvm.git
synced 2026-01-18 03:28:19 +01:00
Release 202412292127
This commit is contained in:
22
ui/src/api.ts
Normal file
22
ui/src/api.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
function api(url: string, options: RequestInit): Promise<Response> {
|
||||
const baseOptions: RequestInit = {
|
||||
mode: "cors",
|
||||
credentials: "include",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
...options,
|
||||
};
|
||||
|
||||
return fetch(url, baseOptions);
|
||||
}
|
||||
|
||||
export default Object.assign(api, {
|
||||
GET: (url: string, options?: RequestInit) => api(url, { method: "GET", ...options }),
|
||||
POST: (url: string, body?: object, options?: RequestInit) =>
|
||||
api(url, { method: "POST", body: JSON.stringify(body), ...options }),
|
||||
PUT: (url: string, body?: object, options?: RequestInit) =>
|
||||
api(url, { method: "PUT", body: JSON.stringify(body), ...options }),
|
||||
DELETE: (url: string, body?: object, options?: RequestInit) =>
|
||||
api(url, { method: "DELETE", body: JSON.stringify(body), ...options }),
|
||||
});
|
||||
Reference in New Issue
Block a user