Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEXTLEVEL 클린코드 리액트 호준] 장바구니 미션 Step1 #7

Open
wants to merge 20 commits into
base: ganeodolu
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: 상품관련 api 추가
ganeodolu committed Feb 25, 2022
commit c6608c567758716b62ad21da97b8cb262cf7c31b
10 changes: 10 additions & 0 deletions client/src/lib/api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import axios from 'axios';

const API = axios.create({
baseURL: "http://localhost:3003",
headers: {
"Content-Type": "application/json",
},
});

export default API
40 changes: 40 additions & 0 deletions client/src/lib/api/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import API from './index';

const apiHandler = {
getProduct: async ({ id }) => {
try {
const response = await API.get(`/products/${id}`)
return response
} catch {
console.log(error);
}
},
getProducts: async () => {
try {
const response = await API.get(`/products/`)
return response
} catch {
console.log(error);
}
},
postProduct: async ({ products }) => {
try {
await API.post({
method: "post",
url: "/products",
data: products,
})
} catch {
console.log(error);
}
},
deleteProduct: async ({ id }) => {
try {
await API.delete(`/product/${id}`)
} catch {
console.log(error);
}
}
};

export default apiHandler