DEV/DEV4.1/tp4/ex1/js/model.js

24 lines
667 B
JavaScript
Raw Normal View History

2024-03-01 15:39:57 +01:00
let apiKey = 'a776e2df'
let model = {
getMovies(search){
return new Promise((resolve, reject) => {
fetch(`http://www.omdbapi.com/?apikey=${apiKey}&s=${search}`)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
resolve(data.Search);
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);}
)
})
}
}
export default model