Skip to content
All essays
WebMarch 25, 202410 min

Browser APIs Deep Dive

Master essential browser APIs: LocalStorage, Fetch, Geolocation, Notifications, and more

Ü
Ümit Uz
Mobile & Full Stack Developer

Modern browsers provide powerful APIs. Let's explore the most essential ones.

LocalStorage & SessionStorage

typescript
// LocalStorage - persists forever
localStorage.setItem('key', 'value');
const value = localStorage.getItem('key');
localStorage.removeItem('key');
localStorage.clear();

// SessionStorage - clears on tab close
sessionStorage.setItem('key', 'value');
const value = sessionStorage.getItem('key');

Fetch API

typescript
// GET request
fetch('https://api.example.com/data')
  .then(response => response.json())
  .then(data => console.log(data));

// POST request
fetch('https://api.example.com/data', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ name: 'John' }),
})
  .then(response => response.json())
  .then(data => console.log(data));

// Async/await
async function fetchData() {
  const response = await fetch('https://api.example.com/data');
  const data = await response.json();
  return data;
}

Conclusion

Browser APIs enable powerful web applications. Master these essentials to build modern, interactive apps.

Related essays

Next essay
Web Workers Guide