Skip to content

Bun 實現了 Web 標准的 fetch API 用於發送 HTTP 請求。要向 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學習網由www.bunjs.com.cn整理維護