Skip to content

Instantly share code, notes, and snippets.

@shershen08
Created November 17, 2022 19:40
Show Gist options
  • Save shershen08/26c70fb18af271f10a944bff46b3cd0e to your computer and use it in GitHub Desktop.
Save shershen08/26c70fb18af271f10a944bff46b3cd0e to your computer and use it in GitHub Desktop.
fetch examples
// 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