Skip to content

PUT rewrite whole data, but might only rewrite what was changed #192

Closed
@adelura

Description

@adelura

Assuming we have following structure:

{
  "posts": [
    {
      "id": 1,
      "authorId": 2,
      "title": "bar"
    },
    {
      "id": 2,
      "authorId": 2,
      "title": "foo"
    }
  ],
  "comments": [
    {
      "id": 1,
      "postId": 1,
      "content": "bar"
    }
  ],
  "authors": [
    {
      "id": 1,
      "name": "Artur Delura"
    },
    {
      "id": 2,
      "name": "Beata Delura"
    }
  ]
}

And there is a request sent to update post title with id 1:

$.ajax({
    url: "http://localhost:2121/posts/1",
    method: "PUT",
    data: {
         title: "baz"
    }
})

Then authorId field in post resource is lost.

I found this issue when I used such request: http://localhost:2121/posts?authorId=1&_embed=comments to get data. After updating I had no posts at all which was very strange :D


I think it's a good idea to change only properties which was intend to be changed. In this case it's only title.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions