budgeteer/web/src/api.ts

30 lines
774 B
TypeScript

import { useSessionStore } from "./stores/session";
export const BASE_URL = "/api/v1";
export function GET(path: string) {
const sessionStore = useSessionStore();
return fetch(BASE_URL + path, {
headers: sessionStore.AuthHeaders,
});
}
export function POST(path: string, body: FormData | string | null) {
const sessionStore = useSessionStore();
return fetch(BASE_URL + path, {
method: "POST",
headers: {
...sessionStore.AuthHeaders,
"Content-Type": "application/json"
},
body: body,
});
}
export function DELETE(path: string) {
const sessionStore = useSessionStore();
return fetch(BASE_URL + path, {
method: "DELETE",
headers: sessionStore.AuthHeaders,
});
}