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

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

Other submissions