Skip to main content

HTML - What is a Web API?

A Web API is a developer's dream. It can extend what the browser can do, greatly simplify complex functions, and provide easy syntax for complex code.


What is Web API?

API stands for Application Programming Interface. An API is an interface with a set of functions and subroutines that let programmers reach specific features or data of an application, operating system, or other service. A Web API is an application programming interface for the web.


HTML APIs

All browsers have a set of built-in Web APIs for complex operations and for reaching data. Some of the main HTML5 APIs are: the Geolocation API, used to get the user's current location (latitude and longitude); the Drag and Drop API, which enables drag-and-drop features; the Web Storage API, which lets browsers store key/value pairs more intuitively than cookies; the Web Workers API, which lets JavaScript run in the background without slowing the page; the Server-Sent Events API, which lets a page automatically receive updates from a server; and the Canvas API, which lets you draw graphics on the fly with JavaScript.


Notes on Using HTML APIs

When using an HTML API, you should always: check browser capability, making sure the target browsers support the API and adding a script or message for those that do not; add robust error handling for cases where the API may not work as expected; and request user permission when the API reaches sensitive data, like the Geolocation API accessing the user's position, by asking for consent first.


Third Party APIs

Third-party APIs are not built into the browser, so to use them you download the code from the web. Examples include the YouTube API (to show videos on a site), the Twitter API (to show tweets), and the Facebook API (to show Facebook information).