fetch('{url}')
.then(response => console.log(response));
| fetch('{url}', {
method: 'post'
})
.then(response => console.log(response));
| simple |
fetch('{url}', {
headers: {
'Authorization': 'Basic {token}'
}
})
.then(response => console.log(response));
| fetch('{url}', {
method: 'post',
headers: {
'Authorization': 'Basic {token}'
}
})
.then(response => console.log(response));
| authorization token (Bearer) |
fetch('{url}?var1=value1&var2=value2')
.then(response => console.log(response));
| fetch('{url}?var1=value1&var2=value2', {
method: 'post'
})
.then(response => console.log(response));
| querystring data |
fetch('{url}', {
mode: 'cors'
})
.then(response => console.log(response));
| fetch('{url}', {
mode: 'cors',
method: 'post'
})
.then(response => console.log(response));
| CORS |
fetch('{url}?var1=value1&var2=value2', {
headers: {
'Authorization': 'Bearer {token}'
}
})
.then(response => console.log(response));
| fetch('{url}?var1=value1&var2=value2', {
method: 'post',
headers: {
'Authorization': 'Bearer {token}'
}
})
.then(response => console.log(response));
| authorization token + querystring data |
| let formData = new FormData();
formData.append('field1', 'value1');
formData.append('field2', 'value2');
fetch('{url}', {
method: 'post',
body: formData
})
.then(response => console.log(response));
| form data |
| fetch('{url}', {
method: 'post',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
'field1': 'value1',
'field2': 'value2'
})
})
.then(response => console.log(response));
| JSON data |
| fetch('{url}', {
method: 'post',
mode: 'cors',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
'field1': 'value1',
'field2': 'value2'
})
})
.then(response => console.log(response));
| JSON data + CORS |