Any Anime

무료
분류별 Kurizu Taz | 업데이트됨 vor 2 Monaten | Video, Images
인기

9.6 / 10

지연 시간

782ms

서비스 수준

100%

Health Check

N/A

모든 토론으로 돌아가기

Difficulty In Fetch Api

Rapid account: Shaikhshahabuddinsadaf
shaikhshahabuddinsadaf
vor 10 Monaten

When used to generate image it is showing me broken or the image url is broken here is the code :

<script>
const API_URL = “https://any-anime.p.rapidapi.com/anime/img”;
const API_KEY = “87f14d9521msh3509002ffa2ec4dp1cb958jsn8f5ba98cab9c”;

const getImage = async () => {
  try {
    const response = await fetch(API_URL, {
      method: "GET",
      headers: {
        "X-Rapidapi-Key": API_KEY,
        "X-Rapidapi-Host": "any-anime.p.rapidapi.com",
        "Host": "any-anime.p.rapidapi.com"
      },
    });

    if (!response.ok) {
      throw new Error("Failed to fetch image.");
    }

    const data = await response.json();

    // Ensure that the image URL is not empty or null
    if (!data.url) {
      throw new Error("Image URL not found.");
    }

    return data.url;
  } catch (error) {
    console.error(error);
    return null;
  }
};

const displayImage = async () => {
  const imageContainer = document.getElementById("image-container");
  imageContainer.innerHTML = "Loading...";

  const imageUrl = await getImage();

  if (imageUrl) {
    imageContainer.innerHTML = `<img src="${imageUrl}" alt="Random Anime Image">`;
  } else {
    imageContainer.innerHTML = "Failed to load image.";
  }
};

document.getElementById("generate-button").addEventListener("click", displayImage);

</script>

Rapid account: Kurizu
Kurizu Commented vor 7 Monaten

I’ve updated the tests and docs on rapid.
Hope the updated docs help !

아래에 의견을 추가하고 토론에 참여하세요.

새 댓글을 게시하려면 로그인 / 가입