ietf-netmod-yangietf-restconf

How to get the specific child element from the parent in restconf


How to get the specific child element from the the parent in restconf, but at the same time to get all the parent's child in restconf? for example: my module

module system{
   leaf name{
      type string;
   }
   leaf version{
      type string;
   }
   container processors{
     list processor{
       key "id";
       leaf id{
         type string;
       }
       leaf name{
         type string;
       }
     }
   }
}

I want all the children of system(name, version, processors) but only the ids of processors :

<system>
  <name>system_1</name>
  <version>1</version>
  <processors>
   <processor>
     <id>1</id>
   </processor>
   <processor>
     <id>2</id>
   </processor>
  </processors>
</system>

what is the query that will invoke that answer in restconf?


Solution

  • You should be able to have this by using the fields query parameter for the GET method. Reference is available in RFC8040 (https://www.rfc-editor.org/rfc/rfc8040#section-4.8.3).

    Request should be something like:

    GET /restconf/data?fields=(system:name;system:version;system:processors/processor/id)

    Note that you need to repeat the module name 'system' multiple times because you haven't defined a common top node in your example model.

    Keep in mind that this works only if the RESTCONF server supports the 'fields' query parameter, which would need to be confirmed first.