PUT and DELETE
Update with PUT (body + id in URL); remove with DELETE.
PUT replaces/updates a resource at a URL (send JSON body).
DELETE asks the server to remove it (often no body).
Set method in the fetch init object. JSONPlaceholder fakes both.
Results appear here.
Important JavaScript
await fetch(url + "/" + id, {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ id: id, title: "…", body: "…", userId: 1 })
});
await fetch(url + "/" + id, { method: "DELETE" });