unfetch demo

by Jason Miller

HTML

<script src="https://unpkg.com/unfetch@1.0.1/dist/unfetch.umd.js"></script>
<pre id="log">Loading...</pre>

Babel + JSX

unfetch('//jsonplaceholder.typicode.com/posts', {
	method: 'POST',
	headers: { 'Content-Type': 'application/json' },
	body: JSON.stringify({
		title: 'foo',
		body: 'bar',
		userId: 1
	})
})
	.then( r => r.json() )
	.then( data => {
		log(data);
		
		unfetch('//jsonplaceholder.typicode.com/posts/1')
			.then( r => r.json() )
			.then( log )
	});



// for demo purposes
function log(t) {
	document.getElementById('log').textContent += '\n\n'+JSON.stringify(t,0,2);
}