import axios from "axios"; export class ApiClient { readonly url = "http://localhost:3000/api"; async get(path: string, params?: URLSearchParams) { const request_url = `${ this.url }${ path }`; const response = await this.makeRequest(request_url); return response; } async getProduct(id: string) { const request_url = `${ this.url }/products/${ id }`; const [product_response, product_reviews] = await Promise.all([ this.makeRequest(request_url), this.makeRequest(`${ request_url }/reviews`) ]); return [product_response, product_reviews]; } private async makeRequest(request_url: string) { try { const response = await axios.get(request_url); return response } catch(error) { return error; } } }