JavaScript Fetch API Cheatsheet




get

fetch('https://jsonplaceholder.typicode.com/todos')
      .then(res => res.json())
      .then(json => console.log(json))

post formdata

const formData = new FormData();
formData.append('name', 'foo');

fetch(`[url]`, { method: 'POST', body: formData})
        .then(res => res.text())
        .then(text => console.log(text))


┬ęCopyright 2019 OneCompiler | Privacy Policy | Terms & Conditions