✅ 프로젝트 진행 중 발생한 오류
(방명록 블로그 오류)
❗ TypeError: Cannot read property 'id' of undefined at Function~
POST 호출 (fetch api)
method 옵션을 POST로 지정, headers 옵션을 통해 JSON 포멧을 사용한다고 알려주고 요청 전문을 JSON 포맷으로 직렬화화해서 body 옵션에 설정해준다.
fetch("https://jsonplaceholder.typicode.com/posts", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
title: "Test",
body: "I am testing!",
userId: 1,
}),
})
.then((response) => response.json())
.then((data) => console.log(data));
//코드 출처 : https://www.daleseo.com/js-window-fetch/
📌 참고자료
https://www.zerocho.com/category/NodeJS/post/579b4ead062e76a002648af7
https://stackoverflow.com/questions/52030845/json-server-getting-error-after-post-request