LEARN: Web API

API, or Application Programming Interface, is a programming concept used frequently in web development. Two programs interact in some manner in an api and data is exchanged. REST apis, like the (far) below example, retrieve data via JS code methods. Two distinct api types separate application development (writing code for an application's functionality) from the application's interaction (writing code to connect third-party programs): 1.) browser apis and 2.) third-party apis.

Browser API

A browser api, like that made for JavaScript, allows DOM interaction, the fetch method - a fetch call sends data requests to third-party api - and others


//Create a new HTML element
document.createElement(tagname);

//Search for page elements
document.querySelector(tagName);
document.getElementById(elementID);
document.getElementByClassName(className);

//Fetch method
fetch(`${apiUrl}`)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error(error));

Third-Party (REST) API

REST api utilizes the URL to make data available using the web. 1. More about URL at URL</RWB>. The below section uses Open Library's api to show results from an api call. Use a name and the search button to interact with the api via a browser click event.

API Fetch Results:

  1. Base Url (string):
  2. Query Parameters (string):
  3. Full Url (URL):

Citations:
[1] What is a REST API? Examples, Uses & Challenges | Postman Blog