0

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?

predi
  • 5,528
  • 32
  • 60

1 Answers1

0

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.

Community
  • 1
  • 1
predi
  • 5,528
  • 32
  • 60
  • augment "aug:aug1"{ container top { list list1 { key "key1 key2 key3"; ... list list2 { key "key4 key5"; ... leaf X { type string; } } } leaf-list Y { type uint32; } } } If I have this type of yang snip, please guide me accordingly. – Tapan Dave Oct 16 '18 at 11:28
  • @TapanDave, the only thing that changes with augmentation is the module name prefix (eg. `example-top:` or `abc:` above) for nodes that are from another module. – predi Oct 16 '18 at 12:47