Skip to content

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 HTML

Per 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();

Bun a cura di www.bunjs.com.cn