Answer the question
In order to leave comments, you need to log in
How to get information by api?
Hello! Please help me figure out api. I do it like this:
const API_KEY = "a1979074-3a11-448a-b2d2-55d1bb97cdf4";
const API_URL_POPULAR =
"https://kinopoiskapiunofficial.tech/api/v2.2/films/1130869";
getMovies(API_URL_POPULAR);
async function getMovies(url) {
const resp = await fetch(url, {
headers: {
"Content-Type": "application/json",
"X-API-KEY": API_KEY,
},
});
const respData = await resp.json();
showMovies(respData);
console.log(respData);
}
function showMovies(data) {
const moviesEl = document.querySelector(".movies");
document.querySelector(".movies").innerHTML = "";
data.forEach((movie) => {
const movieEl = document.createElement("div");
movieEl.classList.add("movie");
movieEl.innerHTML = `
<span>${movie.nameRu}</span>
`;
moviesEl.appendChild(movieEl);
});
}
const API_KEY = "a1979074-3a11-448a-b2d2-55d1bb97cdf4";
const API_URL_POPULAR =
"https://kinopoiskapiunofficial.tech/api/v2.2/films/1130869";
getMovies(API_URL_POPULAR);
async function getMovies(url) {
const resp = await fetch(url, {
headers: {
"Content-Type": "application/json",
"X-API-KEY": API_KEY,
},
});
const respData = await resp.json();
showMovies(respData);
console.log(respData);
}
function showMovies(data) {
const moviesEl = document.querySelector(".movies");
// Очищаем предыдущие фильмы
document.querySelector(".movies").innerHTML = "";
data.genres.forEach((movie) => {
const movieEl = document.createElement("div");
movieEl.classList.add("movie");
movieEl.innerHTML = `
<span>${movie.genre}</span>
`;
moviesEl.appendChild(movieEl);
});
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question