Skip to Content
Hands-On Reactive Programming in Spring 5
book

Hands-On Reactive Programming in Spring 5

by Oleh Dokuka, Igor Lozynskyi
October 2018
Intermediate to advanced
556 pages
15h 18m
English
Packt Publishing
Content preview from Hands-On Reactive Programming in Spring 5

Building a UI with SSE support

The last thing that we need in order to complete our use case is an HTML page with some JavaScript code to communicate with the server. For the sake of conciseness, we will strip all HTML tags and leave only the minimum that is required to achieve a result, as follows:

<body><ul id="events"></ul><script type="application/javascript">function add(message) {    const el = document.createElement("li");    el.innerHTML = message;    document.getElementById("events").appendChild(el);}var eventSource = new EventSource("/temperature-stream");            // (1)eventSource.onmessage = e => {                                       // (2)    const t = JSON.parse(e.data);    const fixed = Number(t.value).toFixed(2);    add('Temperature: ' + fixed + ' C');}eventSource.onopen = e => add('Connection ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Spring Microservices in Action, Second Edition

Spring Microservices in Action, Second Edition

John Carnell, Illary Huaylupo Sanchez

Publisher Resources

ISBN: 9781787284951Supplemental Content