Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

If the user modifies an existing list item and along with that adds a new list item in the payload then once the request is executed the user receives a 200-response code. But upon verifying the data after the request is executed it is seen that only

Expand

Correct parent node xpath: /bookstore/categories[@code=1]

Incorrect JSON payload with newly added list item with title: Book 2

Code Block
{
  "books": [
    {
      "title": "Matilda",
      "lang": "French",
      "editions": [2025]
    },
    {
      "title": "Book 2",
      "lang": "English",
      "authors": ["Test"],
      "editions": [2000]
    }
  ]
}

...

Expand
Code Block
[
  {
    "book-store:books": {
	  "title": "Matilda",
      "lang": "French",

     "authors": ["Roald Dahl"],
      "editions": [2025]
    }
  }
]

It can be seen that only the existing list item, i.e. title: Matilda is replaced. Whereas the newly added list item with title: Book 2 is not added but user received a 200-response code.

Scenario 2: API executes the request with incorrect payload

Another user induced error can occur when the user tries to make changes to the key leaf node, which in the current example is "title". If the key is modified, for example title "Matilda" changed to "Incorrect Book Name", the request should fail because there is no such node present in the database.

But if such an error is intentionally induced to test the functionality of the API, it is seen that the request gets executed with an incorrect payload and the user receives a 200-response code.

...

Correct parent node xpath: /bookstore/categories[@code=1]

...

Expected Behavior

  • Based on the RESTful principles a PUT operation should completely rewrite the data in the database with the new data provided in the payload.

  • So, the expected behavior is to replace all the data of the existing data node and if any new data node is provided as part of the request, then it should be added as a new entity. And the response code should be changed to 204-Created.

Based on the above observations the correct response after data is Replaced should be as follows

Expand
Code Block
{
  "books": [
    {
      "title": "Incorrect Book Name"Matilda",
      "lang": "French",
      "editions": [2025]
    },
    {
      "title": "Book 2",
      "lang": "English",
      "authors": ["FrenchTest"],
      "editions": [20252000]
    }
  ]
}

Proposed/Accepted Solutions

Info

WIP