Basic Web Technologies

Exercise: AJAX Requests

The backend chat service provides a REST API at the URL https://chat.distsys.ch/api.
Update the JavaScript chat.js such that the users and messages are sent to and received from the backend chat service.

Add the following lines of code to pass the authorization token from one page to another:
let authToken = new URLSearchParams(location.search).get('authToken');
if (authToken) {
	for (let link of document.links) link.href += '?authToken=' + authToken;
	username = JSON.parse(atob(authToken.split('.')[1])).sub;
}