Last active
August 8, 2017 15:09
-
-
Save Ai01/4ae8ef47f6104bc4cddac1ef28983188 to your computer and use it in GitHub Desktop.
fetchApi
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
//get | |
fetch('url').then((res)=>{ | |
if(res.ok){ | |
res.json.then((data)=>{ | |
console.log(data); | |
}) | |
} | |
}).catch((err)=>{ | |
console.log(err); | |
}) | |
// post | |
fetch('url',{ | |
method: "POST", | |
headers: { | |
"Content-Type": "application/x-www-form-urlencoded" | |
}, | |
body: "firstName=Nikhil&favColor=blue&password=easytoguess" | |
}).then((res)=>{ | |
if(res.ok){ | |
res.json.then((data)=>{ | |
console.log(data); | |
}) | |
} | |
}).catch((err)=>{ | |
console.log(err); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment