api call in js code example

Example 1: js api call

// Create a request variable and assign a new XMLHttpRequest object to it.
var request = new XMLHttpRequest()

// Open a new connection, using the GET request on the URL endpoint
request.open('GET', 'https://ghibliapi.herokuapp.com/films', true)

request.onload = function () {
  // Begin accessing JSON data here
}

// Send request
request.send()

Example 2: call json api javascript

$.getJSON(
    "API URL HERE",
    function (data){
     console.log(data); // by printing to the console you can easely check all values in the console
      //every api related code here...
    }