Javascript Fetch API Tutorial - Get Request

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

by Yuriy Bablyukh

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 = 'http://localhost:3000/home/ping';
	fetch(url)
  .then(function(response) {
  	// Render the Response Status
  	document.getElementById('result').innerHTML = response.status;
    // Parse the body as JSON
    document.getElementById('result_json').innerHTML = response.body;
    return response.body;
  })
}