18 lines
578 B
TypeScript
18 lines
578 B
TypeScript
|
// Copyright: Ankitects Pty Ltd and contributors
|
||
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||
|
|
||
|
export async function postRequest(path: string, body: string): Promise<Uint8Array> {
|
||
|
const resp = await fetch(path, {
|
||
|
method: "POST",
|
||
|
body,
|
||
|
});
|
||
|
if (!resp.ok) {
|
||
|
throw Error(`unexpected reply: ${resp.statusText}`);
|
||
|
}
|
||
|
// get returned bytes
|
||
|
const respBlob = await resp.blob();
|
||
|
const respBuf = await new Response(respBlob).arrayBuffer();
|
||
|
const bytes = new Uint8Array(respBuf);
|
||
|
return bytes;
|
||
|
}
|