34 lines
881 B
JavaScript
34 lines
881 B
JavaScript
|
let url = "https://jsonplaceholder.typicode.com/users/";
|
||
|
|
||
|
fetch(url)
|
||
|
.then(response => response.json())
|
||
|
.then(data => {
|
||
|
document.getElementById("username").innerHTML += data[2].name;
|
||
|
document.getElementById("email").innerHTML += data[1].email;
|
||
|
})
|
||
|
.catch(data => console.log(data));
|
||
|
|
||
|
// post
|
||
|
let path = "response.json";
|
||
|
fetch(url, {
|
||
|
method: "POST",
|
||
|
headers: {
|
||
|
"Content-Type": "application/json",
|
||
|
},
|
||
|
body: JSON.stringify({
|
||
|
name: "Példa Péter",
|
||
|
email: "pelda_peter@gmail.com"
|
||
|
}),
|
||
|
}).then(response => response.json()).then(data => console.log(data));
|
||
|
|
||
|
//PUT
|
||
|
fetch(url, {
|
||
|
method: "PUT",
|
||
|
headers: {
|
||
|
"Content-Type": "application/json",
|
||
|
},
|
||
|
body: JSON.stringify({
|
||
|
name: "Példa Péter",
|
||
|
email: "pelda_peter@gmail.com"
|
||
|
}),
|
||
|
}).then(response => response.json()).then(data => console.log(data));
|