Bun implementiert die Web-Standard- fetch API zum Senden von HTTP-Anfragen. Um eine einfache GET-Anfrage an eine URL zu senden:
ts
const response = await fetch("https://bun.com");
const html = await response.text(); // HTML-StringUm eine POST-Anfrage an einen API-Endpunkt zu senden.
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();