21 lines
516 B
TypeScript
21 lines
516 B
TypeScript
import fetch from 'cross-fetch';
|
|
|
|
const BASE_URL_V3 = 'https://api.themoviedb.org/3';
|
|
|
|
export default class Api {
|
|
constructor(private accessToken: string) {
|
|
this.accessToken = accessToken;
|
|
}
|
|
|
|
async get<T>(path: string): Promise<T> {
|
|
const response = await fetch(`${BASE_URL_V3}${path}`, {
|
|
method: 'GET',
|
|
headers: {
|
|
Authorization: `Bearer ${this.accessToken}`,
|
|
'Content-Type': 'application/json;charset=utf-8',
|
|
},
|
|
});
|
|
return (await response.json()) as T;
|
|
}
|
|
}
|