import fetch from 'cross-fetch'; import { parseOptions } from './utils'; import { ErrorResponse } from './types'; const BASE_URL_V3 = 'https://api.themoviedb.org/3'; export class Api { constructor(private accessToken: string) { this.accessToken = accessToken; } async get(path: string, options?: Record): Promise { const params = parseOptions(options); const response = await fetch(`${BASE_URL_V3}${path}?${params}`, { method: 'GET', headers: { Authorization: `Bearer ${this.accessToken}`, 'Content-Type': 'application/json;charset=utf-8', }, }); if (!response.ok) { return Promise.reject((await response.json()) as ErrorResponse); } return (await response.json()) as T; } }