Javascript Fetch API Tutorial - Get Request

https://mindsit.net/call-a-rest-web-service-in-javascript-using-fetch-api

by Julien Etienne

HTML

<button onclick="callWs()">
Click
</button>
<br/>
<b>Response Status :</b>
<div id="result">
</div>
<br/>
<b>JSON Object :</b>
<div id="result_json">
</div>

JavaScript

callWs = function(){
	// The Endpoint URL
	let url = 'https://jsonpaceholder.typicode.com/posts/1';
	fetch(url)
  .then(function(response) {
 
  	// Render the Response Status
  	document.getElementById('result').innerHTML = response.status;
    // Parse the body as JSON
    return response.json();
  })
  .then(function(json) {
  	// Render the parsed body
     console.log('json', json)
  	document.getElementById('result_json').innerHTML = JSON.stringify(json);
  })
}