Skip to content

Instantly share code, notes, and snippets.

@pranishabudhathoki
Created October 25, 2021 13:46
Show Gist options
  • Save pranishabudhathoki/f0513a286f360ba53c6f8b38d53d76e5 to your computer and use it in GitHub Desktop.
Save pranishabudhathoki/f0513a286f360ba53c6f8b38d53d76e5 to your computer and use it in GitHub Desktop.
fetching api
//fetching an api
fetch('https://reqres.in/api/users',{
method:'POST',//post data to server
headers:{ //help to know you are passing json
'Content-Type': 'application/json'
},
body: JSON.stringify({ //have to convert to json string
name:'User 1'
})
}).then(res =>
{
return res.json()
})
.then(data => console.log(data))//return promise
.catch(error => console.log('ERROR'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment