title | description | created | updated | color |
---|---|---|---|---|
JavaScript Fetch API |
The Fetch API provides a JavaScript interface for accessing and manipulating parts of the HTTP pipeline, such as requests and responses. |
2018-11-05 |
2018-11-05 |
fetch('https://jsonplaceholder.typicode.com/todos')
.then(res => res.json())
.then(json => console.log(json))
const formData = new FormData();
formData.append('name', 'foo');
fetch(`[url]`, { method: 'POST', body: formData})
.then(res => res.text())
.then(text => console.log(text))
await fetch(`[url]`, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify([dataObject])
}).then(res => res.json())
.then(json => console.log(json))