Created
July 31, 2023 22:40
-
-
Save galvez/f867dd6d6d07db186dc484df659dae57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global.JSON.get = makeMethod('GET') | |
global.JSON.post = makeMethod('POST') | |
global.JSON.put = makeMethod('PUT') | |
function makeMethod (method) { | |
return function (url, options = {}) { | |
const headers = { | |
...options.headers, | |
'Content-Type': 'application/json', | |
} | |
if (typeof options.body === 'object') { | |
options.body = JSON.stringify(options.body) | |
} | |
return fetch(url, { ...options, method, headers }) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment