API with Javascript

API with Javascript

Table of contents

No heading

No headings in the article.

// dog.ceo/api/breeds/image/random

This is the API we will use Usage - This API will give a JSON which will have two things

  1. Image links in https.
  2. Status (Eg: success).

Main code to get that JSON from this API : We will use fetch API of Javascript to get that json:

CODE:

const updateDogImage = async () => {
    const url = `https://dog.ceo/api/breeds/image/random`;
    let data = await fetch(url);
    let parsedData = await data.json();

    let dogImgUrl = parsedData.message;

    //*dogIMGURl will be https://images.dog.ceo/breeds/mountain-bernese/n02107683_4885.jpg*

}

Then in the function, you can use .innerHTML to give this link (dogImgUrl ) to the image tag.

This function is necessary because await will not work without a function. Then with the help of a URL, we can also find the dog breed's name.

labraDogApi.JPG