PUT request deletes some attributes.
for example: In the json.db
{
users:
[
{
"id": 1,
"name": "Leanne Graham",
"username": "Bret",
"email": "[email protected]",
"address": {
"street": "Kulas Light",
"suite": "Apt. 556",
"city": "Gwenborough",
"zipcode": "92998-3874"
}
]
}
Then sending a PUT request to update {"address": {"street": "a new street"}},
the data changed to
{
"users": [
{
"address": {
"street": "json-server-street-23"
},
"id": 1
}
]
}
All other attributes, such as: username, city are deleted. Is it possible to keep all other attributes but just update the street only?
I am using json-api resource on the backend and trying to using json-server to mock all json-api resource functionality.
Thanks!
What you're looking for here is the PATCH method: https://tools.ietf.org/html/rfc5789. Generally speaking, PUT is meant to entire replace a resource with the new attributes, and PATCH should be used for partial application. json-server does provide the PATCH method, and it would seem to suit your needs here.
@drewen This works! I was about to go shoot some ducks! Thanks mate!