Web API - Introduction

Web API is a dream for developers.

  • It can extend the functionality of the browser
  • It can greatly simplify complex functions
  • It can provide simple syntax for complex code

What is Web API?

API refers to the Application Programming Interface (Application Programming Interface).

Web API is the application programming interface of the Web.

Browser API can extend the functionality of the Web browser.

Server API can extend the functionality of the Web server.

Browser API

All browsers have a set of built-in Web APIs to support complex operations and help access data.

For example, the Geolocation API can return the coordinates of the browser's location.

Example

Obtain the longitude and latitude of the user's location:

const myElement = document.getElementById("demo");
function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
  } else {
    myElement.innerHTML = "Geolocation is not supported by this browser.";
  }
}
function showPosition(position) {
  myElement.innerHTML = "Latitude: " + position.coords.latitude +
  "Longitude: " + position.coords.longitude;
}

Try It Yourself

Third-party APIs

Third-party APIs are not built into your browser.

To use these APIs, you must download the code from the Web.

Example:

  • YouTube API - Allows you to display videos on your website.
  • Twitter API - Allows you to display tweets on your website.
  • Facebook API - Allows you to display Facebook information on your website.