7
Send POST Request
One script reply has been approved by the moderators Verified
Created by danielmurvi 1053 days ago Viewed 46868 times
0
Submitted by rubenfiszel Typescript (fetch-only)
Verified 631 days ago
1
export async function main(url: string, body: object = {}, headers: Record<string, string> = {}) {
2
  const resp = await fetch(url, {
3
    method: "POST",
4
    headers: {
5
      "Content-Type": "application/json",
6
      ...headers, 
7
    },
8
    body: JSON.stringify(body),
9
  });
10

11
  return {
12
    ok: resp.ok,
13
    status: resp.status,
14
    text: await resp.text(),
15
  };
16
}
17

Other submissions