Analysis of Replace a Node API
Use Discussion notes to capture meeting items, assign owners, and track actions and decisions.
Date | Item | Owner | Notes | Relevant Links |
---|---|---|---|---|
Aug 9, 2024 |
| @someone | Action |
|
Problem Statement
The Replace Node Leaves API can only perform a replace operation on one data node at a time and in order to perform this request the user needs to provide the following parameters as part of the request:
the parent node xpath of the node being replaced
the JSON/XML payload containing the new data which will replace the existing data.
Scenario 1: API accepts new list items
If a replace operation is performed on a list node, where an already existing list item is being replaced, then in this scenario a user induced error can take place where the user can send a new list item as part of the payload.
This results in a 200-response code being returned to the user but with a partial replace operation.
Because when the data is verified after the replace operation is executed, it is seen that the data of existing list item is replaced, which is the expected behavior. But the data of the new list item is not added under the list node.
But since the API returns a 200-response code, it could create a false sense of security for the user that the request executed successfully, where in fact only a partial operation took place in the database.
A more detailed explanation with examples is as follows:
1. In the following data, the node titled “Matilda",
under the list named “books",
is to be replaced.
2. In order to do so the correct parent node xpath and JSON payload would be as follows:
3. API accepts extra/new list elements as part of request
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
4. The data queried after the above replace operation is executed is as follows:
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.