liveBook · Manning

Web APIs

As explained in Vanilla Web

A programming interface exposed by a web browser for accessing web-platform or device capabilities.

Need storage, device access, or network data in a web app? Check the browser before adding a dependency. Web APIs, also called browser APIs, expose platform capabilities through JavaScript. The DOM is one such interface, not the whole set: other APIs are available through objects including `navigator`, `window`, and `document`. section 2.2.1 section 6.3

Choose the capability that matches the job:

  • Use `fetch()` for data requests, the Cache API for offline caching, and the Performance API for measurements. section 2.2.1
  • Consider storage, geolocation, clipboard, media, notifications, and hardware access where the feature calls for them. section 2.2.1 section 6.3

A Web API does not require a framework, but using one does not prevent direct browser access. Start with widely available APIs; treat experimental features as optional enhancements. Check compatibility in MDN Web Docs or Baseline, and test early on HTTPS or localhost: some APIs need a secure context and may fail or throw errors without one. section 1.5.1 section 2.2.1 section 6.3

if ('permissions' in navigator) {
   navigator.permissions.query({name: "geolocation"})
        .then(console.log);
}

The permission-query example first checks for `navigator.permissions`, then queries geolocation permission. It illustrates checking for an interface before using it; it is not a substitute for checking the capability’s other requirements. section 2.2.1 section 6.3

How Vanilla Web covers it

How deep it goes
Defines the API surface and gives selection and compatibility guidance, but stops short of implementing an end-to-end feature.
Examples
Uses `fetch()`, the Cache API, the Performance API, and a guarded geolocation-permission query as concrete examples.
What it assumes
Assumes working JavaScript for calling browser objects and places APIs alongside HTML and CSS in frontend development.
What you can do after
Practice/perform it: choose a native API for a feature, then check compatibility and secure-context requirements.
How it connects
Connects JavaScript and the DOM to storage, network requests, progressive enhancement, and secure contexts.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Vanilla Web. The section links point to the parts of the book it draws on.