homeman-deno/browser.ts
2024-02-18 09:23:37 -06:00

42 lines
1,006 B
TypeScript

export async function confirmBeforeDo(text: string, cb: () => Promise<void>) {
if (confirm(text)) await cb()
}
export async function GET(path: string) {
const req: RequestInit = {
method: 'GET',
headers: new Headers({
'accept': 'application/json',
}),
}
await fetch(path, req)
}
// deno-lint-ignore no-explicit-any
export async function reqWithBody(method: string, path: string, body: any) {
const req: RequestInit = {
method,
headers: new Headers({
'content-type': 'application/json',
'accept': 'application/json',
}),
body: JSON.stringify(body),
}
await fetch(path, req)
}
// deno-lint-ignore no-explicit-any
export async function POST(path: string, body: any) {
await reqWithBody('POST', path, body)
}
// deno-lint-ignore no-explicit-any
export async function PUT(path: string, body: any) {
await reqWithBody('POST', path, body)
}
// deno-lint-ignore no-explicit-any
export async function DELETE(path: string, body: any) {
await reqWithBody('DELETE', path, body)
}