thomas
This commit is contained in:
16
TP3/EX1/model.js
Normal file
16
TP3/EX1/model.js
Normal file
@@ -0,0 +1,16 @@
|
||||
export async function getMovies(search) {
|
||||
const apiKey = '2fcb2848';
|
||||
const url = `https://www.omdbapi.com/?apikey=${apiKey}&s=${encodeURIComponent(search)}`;
|
||||
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
return data.Search || []; // Renvoie un tableau vide si aucun résultat
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la recherche de films:", error);
|
||||
return [];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user