console.log("hello fetch API");
let myBtn = document.getElementById("myBtn");
let content = document.getElementById("content");
function getData() {
console.log("started getData");
url = "https://api.github.com/users";
fetch(url)
.then((response) => {
console.log("inside first then");
return response.json();
})
.then((data) => {
console.log("inside second then");
console.log(data)
});
}
function postData() {
console.log("started postData");
url = "http://dummy.restapiexample.com/api/v1/create"
data = {"name": "test11", "salary": "123", "age": "23"}
params = {
method : 'post',
headers: {
"Content-type" : "application/json"
} ,
body :JSON.stringify(data)
}
fetch(url,params)
.then(response =>response.json())
.then(data => {
console.log("inside second then")
console.log(data);
console.log(data.data)
});
}
// console.log("before running getData");
// getData();
// console.log("after running getData");
postData();
0 Comments