JavaScript APIs
JavaScript APIs can be categorized into high-level and low-level APIs based on their abstraction and the level of detail they expose to developers. High-level APIs provide more abstraction, making it easier for developers to work with certain functionalities without delving into intricate details. On the other hand, low-level APIs offer more control and detail, allowing developers to fine-tune their implementations.
๐ High-Level JavaScript APIs:
๐ฐ DOM (Document Object Model) API:
Manipulates the structure and content of HTML documents.
Example:
document.getElementById('example').innerHTML = 'New content';
๐ Web API (Fetch API):
Fetches resources across the network asynchronously.
Example:
fetch('
https://api.example.com/data').then(response
.then(response)=> response.json());
๐พ Web Storage API:
Provides methods for storing data on the client side.
Example:
localStorage.setItem('username', 'John');
๐ Geolocation API:
Retrieves the user's geographical location.
Example:
navigator.geolocation.getCurrentPosition(successCallback, errorCallback);
๐จ Canvas API:
Allows dynamic, scriptable rendering of 2D shapes and bitmap images.
Example: Drawing a rectangle on a canvas.
๐ Web Audio API:
Provides advanced audio processing and synthesis capabilities.
Example: Creating and manipulating audio nodes for custom sound effects.
๐ฃ๏ธ Speech Recognition API:
Converts spoken language into text.
Example: Implementing voice commands in a web application.
๐ Intersection Observer API:
Observes changes in the intersection of an element with an ancestor or the viewport.
Example: Lazy loading images as they come into view.
๐ฆท Web Bluetooth API:
Enables web pages to communicate with Bluetooth devices.
Example: Connecting to a Bluetooth-enabled fitness tracker.
๐ฃ๏ธ Web Speech API (Text-to-Speech):
Converts text into spoken language.
Example: Providing an accessibility feature for reading web content aloud.
๐ณ Payment Request API:
Streamlines the payment process on the web.
Example: Initiating a payment request for an online purchase.
๐ถ๏ธ WebXR API (Extended Reality):
Provides access to virtual reality (VR) and augmented reality (AR) devices.
Example: Building immersive VR experiences using WebXR.
๐ Notification API:
Displays system-level notifications to the user.
Example: Notifying users of new messages or updates.
๐ Battery Status API:
Retrieves information about the device's battery.
Example: Adjusting power-intensive features based on battery level.
๐ฅ MediaDevices API (getUserMedia):
Accesses connected media devices like cameras and microphones.
Example: Capturing user's camera input for video conferencing.
โ๏ธ Low-Level JavaScript APIs:
๐ WebGL API:
Renders 3D graphics in the browser using the GPU.
Example: Creating a 3D visualization or game.
๐ WebSockets API:
Enables bidirectional communication between clients and servers.
Example: Real-time chat applications.
๐ ๏ธ Web Workers API:
Runs scripts in the background to perform parallel processing.
Example: Offloading CPU-intensive tasks to improve performance.
๐๏ธ IndexedDB API:
Provides a low-level, asynchronous API for storing large amounts of structured data.
Example: Creating an offline-capable web application with a local database.
๐ File API (deprecated):
Interacts with files on the user's device (deprecated in favor of File System Access API).
Example: Reading and writing files in a browser-based text editor.
๐ก WebRTC API:
Enables real-time communication, including video and audio streaming.
Example: Implementing video conferencing directly in the browser.
๐ Pointer Lock API:
Locks the mouse cursor within a specific element.
Example: Creating immersive first-person navigation experiences.
๐ File System Access API:
Allows web applications to read or save files on the user's device.
Example: Accessing and modifying local files securely.
๐ฎ Gamepad API:
Provides access to game controllers connected to the device.
Example: Implementing game controls for browser-based games.
๐ WebAssembly (Wasm):
Executes low-level code written in languages like C and C++ in the browser.
Example: Boosting performance by running computationally intensive tasks in WebAssembly.
๐ WebCrypto API:
Offers cryptographic operations in the browser.
Example: Encrypting and decrypting data securely in a web application.
๐ WebUSB API:
Enables communication with USB devices.
Example: Interfacing with hardware devices connected via USB.
๐ ๏ธ Service Workers API:
Acts as a proxy between web applications and the network, enabling offline capabilities.
Example: Caching resources for offline access.
๐ WebSocket API:
Facilitates real-time, bidirectional communication between clients and servers.
Example: Building a live updating dashboard.
๐ต Web MIDI API:
Provides access to MIDI devices, allowing web applications to interact with musical instruments.
Example: Creating browser-based music applications.
๐ Hardware-Level JavaScript APIs:
๐ก WebRTC API:
Enables real-time communication, including video and audio streaming.
Example: Implementing video conferencing directly in the browser.
๐ Web NFC API:
Allows web applications to interact with Near Field Communication (NFC) devices.
Example: Reading information from NFC-enabled tags.
๐ณ Vibration API:
Controls the device's vibration hardware.
Example: Providing haptic feedback in response to user actions.
๐ Battery Status API (deprecated):
Retrieves information about the device's battery (deprecated in favor of Battery Status API).
Example: Adjusting power-intensive features based on battery level.
๐ Web Locks API:
Allows web applications to request a lock to prevent conflicts in shared resources.
Example: Synchronizing access to a shared resource in a multi-tab application.
๐ Wake Lock API:
Prevents the device from going to sleep, ensuring that the screen remains active.
Example: Keeping the screen awake during a video playback.
๐ก Web Serial API:
Provides access to serial ports on the user's device.
Example: Communicating with external hardware through serial connections.
๐ง WebHID API:
Enables communication with Human Interface Devices (HID) connected to the device.
Example: Interacting with custom input devices.
๐ฃ๏ธ Web Speech API (Speech Recognition):
Converts spoken language into text.
- Example: Implementing voice commands for hands-free interaction.
๐ Web Audio API (MIDI):
Integrates MIDI controllers with web audio applications.
Example: Creating music using MIDI input in the browser.
๐ Web Authentication API (WebAuthn):
Enables password-less authentication using hardware tokens.
Example: Implementing secure, hardware-backed authentication.
๐ฎ Web Gamepad API:
Provides access to game controllers connected to the device.
Example: Implementing game controls for browser-based games.
๐ WebVR API (deprecated):
Deprecated in favor of WebXR API. Provided access to Virtual Reality (VR) devices.
Example: Building immersive VR experiences using WebVR (deprecated).
๐ก Ambient Light Sensor API:
Retrieves information about the ambient light level around the device.
Example: Adjusting the display brightness based on ambient light.
๐ Proximity Sensor API:
Detects the presence of nearby objects or surfaces.
Example: Implementing gesture-based controls using proximity sensing.
๐ค MediaRecorder API:
Records media streams, such as audio and video.
Example: Implementing a web-based voice recorder or video recorder.