Fetch Url Then Parse Then Handle Catch
Example:
GET::::::::::::::::::::::::::::::::::::::::::::::::::
fetch("http://jservice.io/api/clues")
.then(function(response) {
return response.json()
})
.then(function(data) {
console.log(response)
})
.catch(function(error) {
console.log("error", error.message)
})
POST:::::::::::::::::::::::::::::::::::::::::::::::::::
const data = new FormData ({
key: "value",
gschool: "rocks",
fetch: "rocks"
})
fetch('https://g-echo-request.herokuapp.com/1evt5az1', {
method: "post",
body: data
})
.then(function(response) {
return response.text();
})
.then(function(data) {
console.log(data);
})
.catch(function(error) {
console.log('error:', error.message);
});
AND
fetch('https://galvanize-leader-board.herokuapp.com/api/v1/leader-board', {
method: "POST",
headers: new Headers({
"content-type": "application/json"
}),
body: JSON.stringify({
game_name: "GBP",
player_name: `${nameValue}`,
score: `${score}`
})
})
.then(response => response.json())