This repository has been archived on 2024-12-07. You can view files and clone it, but cannot push or open issues or pull requests.
Cinemateket/src/api/fetchMovie.ts

27 lines
620 B
TypeScript
Raw Normal View History

import { movieResponse } from '../types/movie'
const API_MOVIE_KEY = import.meta.env.VITE_API_MOVIE_KEY
export const fetchMovie = async (
title: string,
page: string = '1',
type?: string,
year?: string
): Promise<movieResponse> => {
let query = `http://www.omdbapi.com/?apikey=${API_MOVIE_KEY}&s=${title}&page=${page}`
if (type) query += `&type=${type}`
if (year) query += `&year=${year}`
const response = await fetch(query)
.then((response) => response.json())
.then((data) => {
return data
})
.catch((error) => {
console.log('Error:', error)
})
return response
}