PUT, PATCH, DELETE Requests

Make REST API update and delete requests using PUT, PATCH, and DELETE.

Code

Utilities
// PUT - Full update
const putResponse = await fetch('https://httpbin.org/put', {
  method: 'PUT',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ id: 1, name: 'Updated', status: 'active' })
});
const putData = await putResponse.json();

// PATCH - Partial update
const patchResponse = await fetch('https://httpbin.org/patch', {
  method: 'PATCH',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ status: 'inactive' })
});
const patchData = await patchResponse.json();

// DELETE
const deleteResponse = await fetch('https://httpbin.org/delete', {
  method: 'DELETE'
});
const deleteData = await deleteResponse.json();

({ put: putData.json, patch: patchData.json, delete: deleteData.method });
Browser·fetch() may be limited by CORS

More JavaScript Snippets