Client와 Server 사이에서의 API 요청법
$ yarn add axios
$ npm install axios
import axios from 'axios';
axios.get('/users/1');
get 이 위치한 자리에는 메서드 이름을 소문자로 넣고. 예를 들어서 새로운 데이터를 등록하고 싶다면 axios.post() 를 사용하면 된다.
그리고, 파라미터에는 API 의 주소를 넣는다.
axios.post() 로 데이터를 등록 할 때에는 두번째 파라미터에 등록하고자 하는 정보를 넣을 수 있다.
프론트에서 데이터 , 파일명, 날짜를 전송이후
백엔드 처리
router.post("/", async (req, res) => {
const request = JSON.parse(req.body.data);
const result = await createExcelJson(
request,
req.body.fileName,
req.body.Date
);
res.send("데이터 들어옴");
}
Front - > back End
.get
params : {data:data } -> req.query.data
.post
new URLSerachParams({data:data}) -> req.body.data