JavaScript: POST JSON with fetch
A short, tested JavaScript example for post json with fetch. Copy it and adjust the names and paths for your project.
JavaScript
const res = await fetch("/api/items", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name: "Zest" }),
});
const created = await res.json();Find it in Zest
Search for “javascript post json with fetch” in Zest and this example appears above the results, with other matches to choose from. Searches stay private.