Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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