Fetch API
fetch() is the built-in way to make HTTP requests in the browser and in Node. It returns a Promise with a Response; call .json() to read the body. fetch doesn't throw on 404 or 500, so check res.ok.
// GET
const res = await fetch("https://jsonplaceholder.typicode.com/posts/1")
if (!res.ok) throw new Error("Request failed: " + res.status)
const post = await res.json()
// POST
await fetch("/api/posts", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ title: "Hello" }),
})