Created
December 13, 2018 22:32
-
-
Save kitsune7/7ebc490d86b9550ddb5d7a8c2119f072 to your computer and use it in GitHub Desktop.
Functions for making a GET or POST request on the client.
This file contains hidden or 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
async function post (url, data) { | |
let request = { | |
body: JSON.stringify(data), | |
method: 'post', | |
headers: { 'Content-Type': 'application/json' } | |
} | |
return fetch(url, request) | |
.then(async (response) => { | |
return response.json() | |
}) | |
.catch((error) => { | |
console.log('Fetch error:', error) | |
return null | |
}) | |
} | |
async function get (url) { | |
let request = { | |
method: 'get', | |
headers: { | |
'Content-Type': 'application/json' | |
} | |
} | |
return fetch(url, request) | |
.then(response => response.json()) | |
.catch((error) => { | |
console.log('Fetch error:', error) | |
return null | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment