fetch api support code example
Example 1: javascript fetch api
fetch('http://example.com/movies.json')
.then((response) => {
return response.json();
})
.then((data) => {
console.log(data);
});
Example 2: fetch api javascript
fetch('http://example.com/songs')
.then(response => response.json())
.then(data => console.log(data))
.catch(err => console.error(err));
Example 3: fetch api javascript
fetch('http://example.com/movies.json')
.then((response) => {
return response.json();
})
.then((myJson) => {
console.log(myJson);
});
Example 4: fetch api
const url = 'http://dummy.restapiexample.com/api/v1/create'
const user = {
name: 'Rahul'
age: '16'
salary: '000'
};
const options = {
method: 'POST'
body: JSON.stringify(user),
}
fetch(url, options)
.then( res => res.json())
.then( res=> console.log(res));
Example 5: fetch
fetch('http://example.com/movies.json')
.then(response => response.json())
.then(data => console.log(data));
Example 6: redirect to website from promise value fetch
fetch("http://example.com/", {
method: 'POST',
mode: 'cors',
body: formData
})
.then(dataWrappedByPromise => dataWrappedByPromise.text())
.then(data => {
window.location.replace(data);
})