Json-server POST 요청 시 message:'Request failed with …tatus:500
by Steady On에러 발생 상황
- Json-server에 연결 후 DB에 POST 요청으로 데이터를 추가할 때 발생한 에러

에러 확인(에러 메세지)
- 콘솔 : POST 500(Internal Server Error)
- 개발자도구 → 네트워크 탭 : TypeError: Cannot read properties of undefined (reading 'id') at Function.createId
원인
- db.jon에 미리 넣어둔 test case에 "id" 가 없어서...
- joson sever에서 만들어지는 db는 자동으로 "id"라는 속성으로 고유의 값을 가지게 되고, 해당 값은 1부터 순서대로 들어가게 됨
- 미리 만들어둔 Test case에 id가 없으면, 이런 에러가 발생.

해결방법
![]() |
![]() |
에러가 발생했을 당시의 DB 모습 | 수정 후 DB 모습 (postId 속성을 id로 변경) |
- 기존에 넣던 id 값이 있다면, 속성명을 "id"로 바꿔준다.(대소문자 주의)
참고자료
https://stackoverflow.com/questions/52030845/json-server-getting-error-after-post-request
json-server getting error after post request
I am working with json-server and I am getting following error. What I am doing wrong? TypeError: Cannot read property 'id' of undefined [0] at Function.createId (/Users/Picchu/Documents...
stackoverflow.com
추가 내용
<id의 속성명을 커스텀 하고 싶을 때 사용할 수 있는 방법>
https://shekhargulati.com/2019/07/10/how-to-setup-json-server-to-use-custom-id-and-route/
How to setup json-server to use custom id and route?
This post talks how to setup json-server to use custom id and routes. In case you don’t know, json-server allows you to run a fake HTTP server with zero coding in no time. This is a common so…
shekhargulati.com
블로그의 정보
Roen의 iOS 개발로그
Steady On