7

I've been searching around but haven't been able to find an answer, if I missed something please just let me know the resource.

I'm building a (mostly) RESTful webservice and need to allow clients to PATCH resources. I realize PATCH by definition isn't RESTful, but I'm still trying to stick as close to the standard as I can.

I'm unsure how to handle patching of properties that are arrays...for instance, my Parent object has multiple Children. So, if someone patches the parent object with a children parameter should I replace existing children or append to them?

Something like

PATCH parent/:id
{
  children: [
    { property: value }
  ]
}

I could just use POST and DELETE on the children to add and remove them from the parent object, but then I want to be able to PATCH the parent object to update other non-array properties, and it seems wrong to allow patching of just some properties and not others. Maybe this is the right answer, I'm not sure.

I've read a lot of posts about proper PATCHing but none of them seem to talk about this issue. If anyone has any input I would appreciate it-

2
  • JSON arrays don't have properties. JSON objects have properties. May 8, 2014 at 2:55
  • Thank you, corrected the oversight in my example object.
    – Pez
    May 8, 2014 at 15:43

1 Answer 1

5

I'd suggest RFC 6902 as some light reading. It fleshes out a good way to handle PATCHing JSON resources.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.