Accessing Individual leaf in leaf in list of yang

1.6k Views Asked by At

I want to access value of leaf of list in yang module? Ex

       module abc
       {
       list xyz{
       key a;
       leaf a{
           type int
       },
       leaf b{
           type string
       },
       leaf c{
           type string
       },
       leaf d{
           type string
       }
       }
       } 

REST should be like "abc/xyz/(which is key)" i.e. (abc/xyz/1)

it will give all values of a,b,c,d.

But if I want to access of individual element b,c,d individual which is non key. How can we write REST API?

1

There are 1 best solutions below

2
On

This is explained in RFC8040, Section 3.5.3. Here's the example from this section:

Examples:

 container top {
      list list1 {
          key "key1 key2 key3";
           ...
           list list2 {
               key "key4 key5";
               ...
               leaf X { type string; }
           }
       }
       leaf-list Y {
         type uint32;
       }
   }

For the above YANG definition, the container "top" is defined in the "example-top" YANG module, and a target resource URI for leaf "X" would be encoded as follows:

  /restconf/data/example-top:top/list1=key1,key2,key3/\
      list2=key4,key5/X

For the above YANG definition, a target resource URI for leaf-list "Y" would be encoded as follows:

  /restconf/data/example-top:top/Y=instance-value

The following example shows how reserved characters are percent-encoded within a key value. The value of "key1" contains a comma, single-quote, double-quote, colon, double-quote, space, and forward slash (,'":" /). Note that double-quote is not a reserved character and does not need to be percent-encoded. The value of "key2" is the empty string, and the value of "key3" is the string "foo".

Example URL:

 /restconf/data/example-top:top/list1=%2C%27"%3A"%20%2F,,foo

So in the context of your example, you would do /restconf/data/abc:xyz=my-key/b, /restconf/data/abc:xyz=my-key/c or /restconf/data/abc:xyz=my-key/d, where my-key is the key of the list instance's entry you wish to query.