노마드코더 유튜브 클론 챌린지 8일차 TIL
GET 서버로부터 데이터를 요청할 때
POST 서버에 데이터를 업데이트할 때
router.jsrouter.get("/", getData);라우터에서
GET방식으로 주소에 접근
controller.jsexport const getData = (req, res) => res.render("home")
home.pug를 렌더링
router.jsrouter.post("/", postData);라우터에서
POST방식으로 주소에 접근
controller.jsexport const postData = (req, res) => { const { data } = req.body; const newData = { item: data } db.push(newData); return res.redirect("/"); }데이터를 가져올 때
body사용
redirect다른 주소로 이동 명령
✅ GET은 렌더링을 함으로써 뭔갈 가져오는걸 하지만
✅ POST는 req로 받은 데이터를 추가한다.
params 주소에 포함된 변수를 담는다
query 주소 ?이후의 변수를 담는다
body req로 받은 데이터를 담는다