Skip to content

Commit

Permalink
merged axios things from feat/teamA
Browse files Browse the repository at this point in the history
  • Loading branch information
anangkf committed Oct 5, 2022
1 parent 15fa0e1 commit daaaeb3
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
2 changes: 2 additions & 0 deletions react-fe-dummyio/.env
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
52 changes: 52 additions & 0 deletions react-fe-dummyio/src/apis/post.js
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;
14 changes: 14 additions & 0 deletions react-fe-dummyio/src/configs/axiosInstance/index.js
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;
6 changes: 6 additions & 0 deletions react-fe-dummyio/src/utils/constans/index.js
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;

0 comments on commit daaaeb3

Please sign in to comment.