Created
November 17, 2022 19:40
-
-
Save shershen08/26c70fb18af271f10a944bff46b3cd0e to your computer and use it in GitHub Desktop.
fetch examples
This file contains 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
// fetch('https://jsonplaceholder.typicode.com/posts/1') | |
// .then(response => response.json()) | |
// .then(json => console.log(json)) | |
// fetch('https://jsonplaceholder.typicode.com/todos/1') | |
// fetch('https://jsonplaceholder.typicode.com/todos/1', { | |
// headers: {}, | |
// method: 'POST', | |
// ... | |
// }) | |
const toSomeething = () => {} | |
let promise = fetch('https://jsonplaceholder.typicode.com/todos/2') | |
promise | |
.then((response) => response.json()) | |
.then(json => { | |
document.querySelector('#content').textContent = json.title | |
document.querySelector('h1').textContent = json.id | |
const IdPlus5 = json.id + 5 | |
toSomeething(json) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment