gistlib
Here's an example using the Fetch API in JavaScript:
index.tsxfetch(url, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(response => { // handle response }) .catch(error => { // handle error }); 205 chars14 lines
fetch(url, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) }) .then(response => { // handle response }) .catch(error => { // handle error });
Alternatively, here's an example using the older XMLHttpRequest API:
index.tsxconst xhr = new XMLHttpRequest(); xhr.open('PATCH', url); xhr.setRequestHeader('Content-Type', 'application/json'); xhr.onreadystatechange = function() { if (xhr.readyState === 4) { // handle response } }; xhr.send(JSON.stringify(data)); 246 chars10 lines
const xhr = new XMLHttpRequest(); xhr.open('PATCH', url); xhr.setRequestHeader('Content-Type', 'application/json'); xhr.onreadystatechange = function() { if (xhr.readyState === 4) { // handle response } }; xhr.send(JSON.stringify(data));
gistlibby LogSnag