Skip to content

Bun は、HTTP リクエストを送信するための Web 標準 fetch API を実装しています。URL にシンプルな GET リクエストを送信するには:

ts
const response = await fetch("https://bun.com");
const html = await response.text(); // HTML 文字列

API エンドポイントに POST リクエストを送信するには:

ts
const response = await fetch("https://bun.com/api", {
  method: "POST",
  body: JSON.stringify({ message: "Hello from Bun!" }),
  headers: { "Content-Type": "application/json" },
});

const body = await response.json();

Bun by www.bunjs.com.cn 編集