Send asynchronous browser requests with fetch, XMLHttpRequest, JSON, errors, and progressive UI.
Lessons
Send API keys safely from the client.
Using API Keys is easiest to learn by reading the example, changing it, and observing the result.
const token = localStorage.getItem('token');
const res = await fetch('/api/profile', {
headers: { 'Authorization': 'Bearer ' + token }
});
if (res.status === 401) {
location.href = '/login';
} else {
console.log(await res.json());
}Practice the Using API Keys example in a small scratch file, then explain what changed and why.