From ca31ad261bcd7942f62c07183163995afc24e108 Mon Sep 17 00:00:00 2001 From: ByungyeonKim Date: Tue, 2 Nov 2021 18:38:53 +0900 Subject: [PATCH] =?UTF-8?q?Fetch=20API=EC=97=90=EC=84=9C=20Axios=EB=A1=9C?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/src/service/contents.js | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/public/src/service/contents.js b/public/src/service/contents.js index ed0caaa..e2d13ee 100644 --- a/public/src/service/contents.js +++ b/public/src/service/contents.js @@ -1,35 +1,21 @@ class Contents { - constructor() { - this.baseURL = 'http://localhost:3000/api'; - this.getRequestOptions = { - method: 'GET', - redirect: 'follow', - }; + constructor(httpClient) { + this.contents = httpClient; } async getContents(name) { - const res = await fetch( - `${this.baseURL}/content/${name}`, - this.requestOptions - ); - - const result = await res.json(); - return result; + const res = await this.contents.get(`content/${name}`); + return res.data; } async realTimeBest() { - const res = await fetch(`${this.baseURL}/best`, this.requestOptions); - const result = await res.json(); - return result; + const res = await this.contents.get('best'); + return res.data; } async detailPage(url) { - const res = await fetch( - `${this.baseURL}/detail/${url}`, - this.requestOptions - ); - const result = await res.json(); - return result; + const res = await this.contents.get(`detail/${url}`); + return res.data; } }