Skip to content

Instantly share code, notes, and snippets.

@Ai01
Last active August 8, 2017 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ai01/4ae8ef47f6104bc4cddac1ef28983188 to your computer and use it in GitHub Desktop.
Save Ai01/4ae8ef47f6104bc4cddac1ef28983188 to your computer and use it in GitHub Desktop.
fetchApi
//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