Introduction to Browser APIs
#
But first, what is an API?Application Programming Interfaces (APIs) are constructs made available in programming languages to allow developers to create complex functionality more easily. They abstract more complex code away from you, providing some easier syntax to use in its place.
-MDN, Client-Side Web APIs - Introduction
#
APIs in Client-Side JavaScriptWhen we deal with client-side JavaScript, there are many powerful APIs available on it, which aren't part of the JavaScript language itself, but built on top of it. They are broadly categorised into:
- Third-Party APIs, which are not built into the browser by default, and require you to interface with them through the internet (i.e. through a REST API over HTTP, or WebSockets!)
- Browser APIs are built into the web browser and are able to expose data and functionality from the browser and the computer. We will primarily be concerning ourselves with Browser APIs for this section.
Examples of Browser APIs:
- DOM - allows you to manipulate the DOM
- WebSockets, WebRTC - to help you build real-time web applications!
- Notifications - allows you to show notifications on the desktop / mobile device
- Canvas - allows you to manipulate graphics in a HTML
<canvas>
element - GeoLocation - allows you to get the geolocation information of the device
- Vibration - allows you to cause the device to vibrate
Again, MDN is the most definitive resource regarding these APIs