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/frontend/src/api/fetchMovie.ts
haraldnilsen 1c19ca4ee2 working connection between frontend and backend
Co-authored-by: Sindre Kjelsrud <kjelsrudsindre@gmail.com>
2023-10-02 12:20:27 +02:00

26 lines
No EOL
641 B
TypeScript

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