Skip to content

Instantly share code, notes, and snippets.

@stafordtituss
Created March 4, 2020 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stafordtituss/5f651696ef19482b755a7d69437246db to your computer and use it in GitHub Desktop.
Save stafordtituss/5f651696ef19482b755a7d69437246db to your computer and use it in GitHub Desktop.
HTTP Readable Stream using fetch - CLIENT SIDE (HTML and Vanilla JS) < An example for getting artillery report stream >
<!DOCTYPE html>
<html>
<head>
<title>Artillery Report Generation</title>
</head>
<body>
<h1>ARTILLERY REPORT GENERATION</h1>
<p>Click the button to run the test and generate the report!!</p>
<button>RUN</button>
<script>
const button = document.querySelector('button');
button.addEventListener('click', function() {
fetch('http://localhost:8000', {method: 'post'})
.then(response => {
const reader = response.body.getReader();
reader.read().then(function loop({done, value}) {
const chunk = String.fromCharCode.apply(null, new Uint8Array(value));
console.log(chunk);
document.write(chunk);
document.write("<br>");
return reader.read().then(loop);
});
})
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment