Search code examples
json-server

JSON server - Is it possible to update an object id?


Here is my db.json :

{
  "users": [
    {
      "id": "1"
      "name": "John"
    }
  ]
}

I'd like to be able to update the user id by sending a PUT request on the existing user. But the following does not work:

Request URL :

PUT /users/1

with body:

{
  "id": "2"
  "name": "John"
}

Is there a way to update an object id?


Solution

  • This does not seem to be possible, as said in documentation:

    Id values are not mutable. Any id value in the body of your PUT or PATCH request will be ignored. Only a value set in a POST request will be respected, but only if not already taken.