iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

Web API Intro

Web APIs are built-in browser interfaces exposed to JavaScript. They cover everything from networking and storage to graphics, audio, and the camera.

The most-used Web APIs

APIWhat it does
DOMRead and change the page.
FetchHTTP requests (replaces XMLHttpRequest).
Web StoragelocalStorage, sessionStorage.
IndexedDBLarger structured client-side database.
GeolocationRead the device's coordinates.
Web WorkersRun JS off the main thread.
Service WorkersOffline, caching, push notifications.
WebSocketPersistent, two-way connections.
WebRTCPeer-to-peer audio/video/data.
Canvas / WebGL / WebGPU2D / 3D graphics.
Web AudioSynthesize and process audio.
Notifications / PushOS-level alerts.
Intersection / Resize / Mutation ObserverReact to layout and DOM changes.

Detecting support

JS
if ("clipboard" in navigator)             { /* … */ }
if (typeof IntersectionObserver !== "undefined") { /* … */ }
if ("serviceWorker" in navigator)         { /* register SW */ }

Permissions

Sensitive APIs (camera, microphone, location, notifications) require explicit user consent. The Permissions API lets you check current state without prompting:

JS
const status = await navigator.permissions.query({ name: "geolocation" });
status.state;       // "granted" | "denied" | "prompt"
Tip: Bookmark MDN's Web API index. Hundreds of APIs exist — feature-detect before reaching for the ones outside the every-day list.

Example

Example
<!DOCTYPE html>
<html>
<body>

<p id="out"></p>

<script>
document.getElementById("out").textContent = "Hello from Web API Intro!";
</script>

</body>
</html>
Try it Yourself »

Exercise

Check permission state for geolocation without prompting.

const s = await navigator. .query({ name: 'geolocation' });

Test yourself

Q1. Sensitive APIs (camera, geolocation, notifications)…
Q2. Detect support cleanly with…
Q3. Query permission state without prompting via…

Discussion

Loading…