Web APIs Reference

Learn what browser APIs do, where to use them, and how to start. Expand any API for a short explanation, safe example, and a link to its official documentation.

15 of 15 APIs shown
Fetch APINetwork

Send HTTP requests and read responses using promises.

Works with URLs permitted by browser networking and CORS rules.

Example

const response = await fetch('/api/status');
if (!response.ok) throw new Error('Request failed');
const data = await response.json();

Practical uses

  • Requesting JSON
  • Submitting forms
  • Uploading files
Read MDN documentation ↗
WebSocket APINetwork

Keep an interactive, bidirectional connection to a server.

Use wss:// on HTTPS websites and handle reconnections.

Example

const socket = new WebSocket('wss://example.com/events');
socket.addEventListener('message', e => console.log(e.data));

Practical uses

  • Live collaboration
  • Chat updates
  • Streaming dashboards
Read MDN documentation ↗
Web Storage APIStorage

Persist small string values in localStorage or per-tab sessionStorage.

Storage is synchronous and may be unavailable; avoid storing secrets.

Example

localStorage.setItem('theme', 'dark');
const theme = localStorage.getItem('theme') ?? 'light';

Practical uses

  • Preferences
  • Draft forms
  • Short session state
Read MDN documentation ↗
IndexedDB APIStorage

Store larger structured records and indexes in the browser.

Transactions are asynchronous; upgrades define object stores.

Example

const request = indexedDB.open('notes', 1);
request.onupgradeneeded = () => {
  request.result.createObjectStore('items', { keyPath: 'id' });
};

Practical uses

  • Offline records
  • Searchable datasets
  • Caching structured data
Read MDN documentation ↗
Clipboard APIBrowser

Copy text or interact with the clipboard after appropriate user interaction.

Generally requires a secure context; browser permissions and user gestures apply.

Example

await navigator.clipboard.writeText('Hello LangSteps');

Practical uses

  • Copy code
  • Copy links
  • Paste workflows
Read MDN documentation ↗
Geolocation APIBrowser

Request the user's location with their permission.

Requires user consent and a secure context; never request it automatically.

Example

navigator.geolocation.getCurrentPosition(
  pos => console.log(pos.coords.latitude),
  err => console.error(err.message)
);

Practical uses

  • Location-aware maps
  • Local search
  • Weather widgets
Read MDN documentation ↗
Notifications APIBrowser

Show system notifications when the user has granted permission.

Request permission only in response to an explicit user action; support varies.

Example

const permission = await Notification.requestPermission();
if (permission === 'granted') new Notification('Ready!');

Practical uses

  • Reminders
  • Status alerts
  • User-requested updates
Read MDN documentation ↗
Web Share APIBrowser

Open the operating system's native share interface where supported.

Typically requires HTTPS and a direct user gesture; provide a fallback link.

Example

if (navigator.share) {
  await navigator.share({ title: 'LangSteps', url: location.href });
}

Practical uses

  • Sharing articles
  • Sharing URLs
  • Mobile share sheets
Read MDN documentation ↗
Intersection Observer APIPerformance

Observe when elements enter or leave the viewport without scroll polling.

Disconnect observers when no longer needed.

Example

const observer = new IntersectionObserver(entries => {
  for (const entry of entries) {
    if (entry.isIntersecting) console.log('Visible');
  }
});

Practical uses

  • Lazy-loading
  • Reading progress
  • Infinite lists
Read MDN documentation ↗
Web Workers APIPerformance

Move CPU-intensive JavaScript work away from the main UI thread.

Workers do not directly manipulate the document DOM.

Example

const worker = new Worker('./worker.js');
worker.postMessage({ task: 'summarize' });
worker.onmessage = event => console.log(event.data);

Practical uses

  • Data parsing
  • Background computation
  • Image processing
Read MDN documentation ↗
Service Worker APIPerformance

Intercept selected network requests for offline-capable web applications.

HTTPS is generally required. Scope caches carefully to your own app.

Example

if ('serviceWorker' in navigator) {
  await navigator.serviceWorker.register('./sw.js');
}

Practical uses

  • Offline lessons
  • Asset caching
  • Background synchronization
Read MDN documentation ↗
Canvas APIMedia

Draw graphics, charts, sprites, and pixel data on an HTML canvas.

Always confirm the drawing context exists before using it.

Example

const canvas = document.querySelector('canvas');
const ctx = canvas.getContext('2d');
ctx.fillRect(10, 10, 100, 60);

Practical uses

  • Games
  • Charts
  • Image editing
Read MDN documentation ↗
Web Audio APIMedia

Generate, route and analyze audio inside the browser.

Audio playback commonly needs a user gesture before resuming.

Example

const audio = new AudioContext();
const gain = audio.createGain();
gain.connect(audio.destination);

Practical uses

  • Audio visualizers
  • Sound synthesis
  • Accessibility audio
Read MDN documentation ↗
Web Animations APIMedia

Control element animations programmatically with keyframes and timing.

Respect prefers-reduced-motion when designing animations.

Example

document.querySelector('.card')?.animate(
  [{ opacity: 0 }, { opacity: 1 }],
  { duration: 250, fill: 'forwards' }
);

Practical uses

  • Interactive UI
  • Entrance transitions
  • Timeline controls
Read MDN documentation ↗
Web Crypto APISecurity

Use browser cryptographic primitives for digest and key operations.

Use established protocols and authenticated cryptography rather than custom designs.

Example

const data = new TextEncoder().encode('hello');
const hash = await crypto.subtle.digest('SHA-256', data);

Practical uses

  • Integrity checks
  • Key derivation
  • Secure applications
Read MDN documentation ↗