0

I am creating a post rest endpoint that will create resource 'child'. My uri is:

/parents/{parentId}/child

What are the rest standards for the content of the body for this request? Should the data be related only to the child resource (option 1) or should the parent id be present in the body (option 2) along with being present in the uri?

Option 1:

{
   name: 'name',
   age: '10'
}

Option 2:

{
   parentId: 'abc'
   name: 'name',
   age: '10'
}
bdeane
  • 52
  • 9
  • What do you believe should happen if the content has a `parentId`, and the value differs from the value given in the *path*? Ignore and use one of them? Which one? Fail? If so, why even ask for the value twice? --- Better to only require the value once, and since it's already in the *path*, use option 1. – Andreas Jul 15 '20 at 09:26

1 Answers1

0

I think the best is option 1 and you set your parent in your logic otherwise you must reflect the object relation if you use Option 2

{
   parent: {
    id: 'abc'
   },
   name: 'name',
   age: '10'
}

this way if you delegate serialization to a converter it will create directly the parent node

Idriss Sakhi
  • 267
  • 2
  • 5