Bun implementa l'API fetch standard Web per inviare richieste HTTP. Per inviare una semplice richiesta GET a un URL:
ts
const response = await fetch("https://bun.com");
const html = await response.text(); // Stringa HTMLPer inviare una richiesta POST a un endpoint API.
ts
const response = await fetch("https://bun.com/api", {
method: "POST",
body: JSON.stringify({ message: "Ciao da Bun!" }),
headers: { "Content-Type": "application/json" },
});
const body = await response.json();