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