2

I would like to update an embedded document through an Api request and don't want to PUT the whole parent resource:

Parent {
  _id: 123,
  ...
  events: [
    ...
    ...
  ]
}

To update the embedded document, RFC 6902 A.16 suggests:

PATCH /parent-resource/123
[
  { "op": "add", "path": "/events/-", "value": {new event obj}}
]

Success Response: 204 no-content

I do like this quite a bit and will offer this. But for slightly easier use, would an alias of:

POST /parent-resource/123/events
{new event object}

Success Response: 204 no-content

also be acceptable? Also, what are some good resources regarding JSON Api standards?

Community
  • 1
  • 1
dhudson
  • 571
  • 3
  • 9
  • does this have anything to do with mongodb? You're talking about how to manipulate JSON, mongodb stores BSON and provides its own CRUD syntax, in particular, update operation which can $set or otherwise change various fields in the document. – Asya Kamsky Apr 01 '14 at 18:15
  • 1
    More generally, building Api routes using a document database (mongodb in my case)... I do understand the DB CRUD and that is not my issue. I am more curious about RESTful Api standards specifically related resources that contain embedded documents. – dhudson Apr 01 '14 at 19:13
  • It's surprising there has been no further interest in this topic. The semantics of patching a document-oriented database over HTTP seems to me to be fundamental to modern software development. – Tom Russell Sep 16 '17 at 06:18
  • 1
    @TomRussell There's been a lot of interest on this topic, but it's scattered all over the web. – HappyNomad Jan 17 '18 at 17:40

0 Answers0