POST request not working

Post request not working
below is my db.json file

  "feedback": [
      "id": "1",
      "rating": 10,
      "text": "This is feedback item 1 coming from the backend"
      "id": "2",
      "rating": 8,
      "text": "This is feedback item 2 coming from the backend"

I installed json-server in vs-code

get request is working in postman api application

But Getting this error for POST request

Error is

K-K-Harjeeth:feedback-app kk_harjeeth$ npm run server

> feedback-app@0.1.0 server
> json-server --watch db.json --port 6000

--watch/-w can be omitted, JSON Server 1+ watches for file changes by default
JSON Server started on PORT :6000
Press CTRL-C to stop
Watching db.json...

♡⸜(˶˃ ᵕ ˂˶)⸝♡


Static files:
Serving ./public directory if it exists

SyntaxError: Unexpected token r in JSON at position 0
    at JSON.parse (<anonymous>)
    at file:///Users/kk_harjeeth/feedback-app/node_modules/milliparsec/dist/index.js:21:45
    at file:///Users/kk_harjeeth/feedback-app/node_modules/milliparsec/dist/index.js:8:16
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async file:///Users/kk_harjeeth/feedback-app/node_modules/milliparsec/dist/index.js:21:20
    at async file:///Users/kk_harjeeth/feedback-app/node_modules/@tinyhttp/app/dist/index.js:169:7
    at async file:///Users/kk_harjeeth/feedback-app/node_modules/@tinyhttp/app/dist/index.js:434:7

We have no idea what that API will accept.

However, as its complaining about JSON, it’s worth noting that you aren’t sending a JSON request but x-www-form-urlencoded.

So if your API can’t handle that type of request and is actually expecting JSON, that might account for the error.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.