Fetch API

Posted 2 years ago

fetch('https://www.barberriley.com/api/some/url').then(function(res) {
	console.log(res);
}).catch(function(error) {
	console.log(error);
});

Adding headers to the call


fetch('https://www.barberriley.com/api/some/url.json', {
	method: 'POST', 
	mode: 'cors', 
	redirect: 'follow',
	headers: new Headers({
		'Content-Type': 'text/plain'
	})
}).then(function() { /* handle response */ });