A Pen by pranishabudhathoki on CodePen.
Created
October 25, 2021 13:46
-
-
Save pranishabudhathoki/f0513a286f360ba53c6f8b38d53d76e5 to your computer and use it in GitHub Desktop.
fetching api
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
//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