moved option parsing in superclass 'get' method
This commit is contained in:
@@ -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<T>(path: string): Promise<T> {
|
||||
const response = await fetch(`${BASE_URL_V3}${path}`, {
|
||||
async get<T>(path: string, options?: Record<string,any>): Promise<T> {
|
||||
const params = parseOptions(options);
|
||||
const response = await fetch(`${BASE_URL_V3}${path}?${params}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Authorization: `Bearer ${this.accessToken}`,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export function parseOptions(
|
||||
options?: { [s: string]: any },
|
||||
options?: Record<string, any>,
|
||||
): string {
|
||||
return options
|
||||
? new URLSearchParams(Object.entries(options)).toString()
|
||||
|
||||
Reference in New Issue
Block a user