WHAT IS WEB API | HTML WEB API
If you're asking about HTML Web APIs, these are browser-provided interfaces that let web pages interact with the browser, device, and web platform. HTML itself provides structure, while JavaScript uses Web APIs to add functionality.
Here are some of the most common Web APIs:
| API | Purpose | Example |
|---|---|---|
| DOM API | Access and modify HTML elements | Change text, styles, attributes |
| Fetch API | Request data from servers | Load JSON from an API |
| Geolocation API | Get user's location | GPS coordinates |
| Local Storage API | Store data in the browser | Save user preferences |
| Session Storage API | Store temporary data | Shopping cart during a session |
| Canvas API | Draw graphics | Games, charts, animations |
| Web Audio API | Play and manipulate audio | Music players |
| WebRTC API | Real-time audio/video communication | Video calls |
| WebSocket API | Two-way communication | Live chat |
| Notification API | Show desktop notifications | Message alerts |
| Clipboard API | Read/write clipboard | Copy and paste |
| Drag and Drop API | Drag elements on a page | File uploads |
| History API | Manipulate browser history | Single-page applications |
| Fullscreen API | Enter fullscreen mode | Video players |
| File API | Read local files | Image preview before upload |
Example: Fetch API
<!DOCTYPE html> <html> <body> <button onclick="loadData()">Load Data</button> <p id="result"></p> <script> async function loadData() { const response = await fetch("https://jsonplaceholder.typicode.com/posts/1"); const data = await response.json(); document.getElementById("result").textContent = data.title; } </script> </body> </html>
Example: Local Storage API
<input type="text" id="name"> <button onclick="saveName()">Save</button> <script> function saveName() { const name = document.getElementById("name").value; localStorage.setItem("username", name); alert("Saved!"); } </script>
Example: Geolocation API
<button onclick="getLocation()">Get Location</button> <script> function getLocation() { navigator.geolocation.getCurrentPosition(position => { alert( "Latitude: " + position.coords.latitude + "\nLongitude: " + position.coords.longitude ); }); } </script>
Categories of Web APIs
-
Browser APIs
- DOM API
- Fetch API
- History API
- Storage API
- Clipboard API
- Fullscreen API
-
Device APIs
- Geolocation API
- MediaDevices API (camera and microphone)
- Battery API (limited support)
-
Graphics APIs
- Canvas API
- WebGL API
- SVG API
-
Communication APIs
- Fetch API
- WebSocket API
- WebRTC API
Web APIs are not part of HTML itself. They are provided by web browsers and are typically accessed using JavaScript to create interactive web applications.
No comments