diff --git a/src/api.ts b/src/api.ts index 9908780..e4d677d 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,4 +1,5 @@ import fetch from 'cross-fetch'; +import { parseOptions } from './utils'; const BASE_URL_V3 = 'https://api.themoviedb.org/3'; @@ -7,8 +8,9 @@ export default class Api { this.accessToken = accessToken; } - async get(path: string): Promise { - const response = await fetch(`${BASE_URL_V3}${path}`, { + 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}`, diff --git a/src/utils/parseOptions.ts b/src/utils/parseOptions.ts index 9066db5..5527756 100644 --- a/src/utils/parseOptions.ts +++ b/src/utils/parseOptions.ts @@ -1,5 +1,5 @@ export function parseOptions( - options?: { [s: string]: any }, + options?: Record, ): string { return options ? new URLSearchParams(Object.entries(options)).toString()