fetch API 用于发送 HTTP 请求。要向一个 URL 发送一个简单的 GET 请求:
向 API 端点发送
POST 请求。
fetch API 用于发送 HTTP 请求。要向一个 URL 发送一个简单的 GET 请求:
const response = await fetch("https://bun.com");
const html = await response.text(); // HTML 字符串
POST 请求。
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();