1

Is it possible to send a single request of creating multiple resources at the top-level to a RESTCONF server?

For example, consider the following YANG module:

 module example-foomod {

 namespace "http://example.com/foomod";

 prefix "foomod";

 container top {
   container under1{
     leaf foo {
       type uint8;
     }
   }
   container under2{
     leaf bar {
       type uint8;
     }
   }
 }

}

Can I send the following request to create two resources one time? Or Must I create one resource at a time?

POST /restconf/data/example-foomod:top

payload is:

{
 "example-foomod:under1": {
   "foo": 54
 },
 "example-foomod:under2": {
   "bar": 45
 }
}

I didn't find answer in RFC7951. It seems like all examples in that RFC are single resource, like in section4.

Community
  • 1
  • 1
password636
  • 981
  • 1
  • 7
  • 18
  • Your example does not reflect your question. There is only one top-level resource in your example, defined by `container top`. Therefore your payload is actually creating a single object that happens to have two children. If you add the missing comma, there the request would be valid. – predi Oct 23 '18 at 13:35
  • @predi I've added the missing comma in payload. Thank you for pointing it out. Maybe I'm using wrong terms to describe my question. Yes, I want to know if the request is valid or not. And you are saying that the payload is creating a single object. Is the single object created `/restconf/data/example-foomod:top`? – password636 Oct 24 '18 at 05:18
  • @predi But target resource for POST is not the resource to create, Post is to create child resources within target resource, so the resources created should be two: `"example-foomod:under1"` and `"example-foomod:under2"`. If the POST succeeds, what resource URI should return in `"Location" `header? Still `/restconf/data/example-foomod:top`? – password636 Oct 24 '18 at 05:18
  • The implementation available to me (tail-f confd), accepts the payload and creates both `under1` and `under2`. Curiously, it returns Location to be that of `under1`. After re-reading the related RFC sections I see the text is indeed unclear. Such requests should probably fail. Depends on how you interpret `The message-body MUST contain exactly one instance of the expected data resource.` There is exactly one instance - for each... – predi Oct 24 '18 at 07:56
  • @ predi Is your last comment complete? – password636 Oct 26 '18 at 02:56
  • Yes. I was referring to RFC8040, though. Failed to notice it was never mentioned before. What I meant with that last sentence is that you could probably apply that RFC text to both `under1` and `under2` separately and not violate the MUST. It is more likely that the authors meant `The message-body MUST contain exactly one instance of the single expected data resource` or something along those lines. – predi Oct 26 '18 at 09:08
  • @predi I read the lines in RFC8040 again and from the line before: `The message-body is expected to contain the content of **a child resource** to create within the parent (target resource). The message-body MUST contain exactly one instance of the expected data resource.` Can it be a hint to mean single data resource because it uses `a child resource`. So my payload example should probably fail by RFC? – password636 Oct 29 '18 at 02:58
  • Yes, the payload should probably fail. – predi Nov 09 '18 at 13:14

0 Answers0