Question

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-

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top