forked from syukronarie/react-a-batch-3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
REACT_APP_KEY_ID=633d7be32ba9895e992d72a5 | ||
REACT_APP_BASE_URL=https://dummyapi.io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import axiosInstance from '../configs/axiosInstance' | ||
|
||
const APIPost = { | ||
async getlistbytag(tagId) { | ||
try { | ||
const response = await axiosInstance.get("/tag/"+tagId+"/post"); | ||
return response; | ||
} catch (err) { | ||
const { message } = err.response.data; | ||
throw new Error(message); | ||
} | ||
}, | ||
async createPost(data) { | ||
try { | ||
const response = await axiosInstance.post("/post/create", data); | ||
return response; | ||
} catch (err) { | ||
const { message } = err.response.data; | ||
throw new Error(message); | ||
} | ||
}, | ||
async getPostById(postId) { | ||
try{ | ||
const response = await axiosInstance.get("/post/"+postId); | ||
return response; | ||
} catch(err){ | ||
const { message } = err.response.data; | ||
throw new Error(message); | ||
} | ||
}, | ||
async getListByUser(userId) { | ||
try{ | ||
const response = await axiosInstance.get("/user/"+userId+"/post"); | ||
return response; | ||
} catch(err) { | ||
const { message } = err.response.data; | ||
throw new Error(message); | ||
} | ||
}, | ||
async getList() { | ||
try { | ||
const response = await axiosInstance.get("/post"); | ||
return response; | ||
} catch (err) { | ||
const { message } = err.response.data; | ||
throw new Error(message); | ||
} | ||
}, | ||
|
||
} | ||
|
||
export default APIPost; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import axios from "axios"; | ||
import CONST from "../../utils/contants"; | ||
|
||
const config = { | ||
baseURL: CONST.BASE_URL_API, | ||
headers: { | ||
"app-id": CONST.REACT_APP_KEY_ID, | ||
} | ||
}; | ||
|
||
const axiosInstance = axios.create(config); | ||
|
||
|
||
export default axiosInstance; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const CONST = { | ||
BASE_URL_API: `${process.env.REACT_APP_BASE_URL}/v1`, | ||
REACT_APP_KEY_ID: process.env.REACT_APP_KEY_ID, | ||
}; | ||
|
||
export default CONST; |