Skip to content

Commit 7475f54

Browse files
committed
Test REST request
1 parent 2c2cdb1 commit 7475f54

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

experimental/test-login.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@ if (loggedInUser) {
4444
+ '<a href="' + serviceUrl + '/logout">'
4545
+ 'LOG OUT'
4646
+ '</a>';
47+
48+
console.log('Testing a REST request...');
49+
fetch('/api/profile', { method: 'GET', headers: { 'Content-Type': 'application/json' } })
50+
.then(function (data) {
51+
if (data.ok) {
52+
return data.json();
53+
} else {
54+
throw new Error('Server Error: ' + data.statusText);
55+
}
56+
})
57+
.then(function (json) {
58+
console.log('Request successful:');
59+
console.log(JSON.stringify(json));
60+
})
61+
.catch(function (error) {
62+
console.error('REST request failed: ' + error.toString());
63+
});
4764
} else {
4865
// prettier-ignore
4966
rootDiv.innerHTML = 'You are not logged in'

0 commit comments

Comments
 (0)