Thursday, December 14, 2023

Get API CAll (Promise) & Other call (Request) seperate in java script

 In JAVASCRIPT


async function fetApi(){
      // Get the character ID from the input field
      const characterId = document.getElementById('characterId').value;

      // Construct the SWAPI URL for the specific character
      const swapiUrl = `https://swapi.dev/api/people/${characterId}/`;

      let res=await fetch(swapiUrl);
      let resJson= await res.json();
      return resJson;
    }
    
    // REquest Decode

    async function f1(){
      const jsonData= await fetApi();
      console.log("DATA:-",jsonData);
        // console.log("NAme:-" , jsonData['name']);
    }

No comments:

Post a Comment