Bun 實作了 Web 標準的 fetch
API 以發送 HTTP 請求。要發送一個簡單的 GET
請求到 URL
const response = await fetch("https://bun.dev.org.tw");
const html = await response.text(); // HTML string
要發送 POST
請求到 API 端點。
const response = await fetch("https://bun.dev.org.tw/api", {
method: "POST",
body: JSON.stringify({ message: "Hello from Bun!" }),
headers: { "Content-Type": "application/json" },
});
const body = await response.json();