Given the following YANG definitions, in module test
:
list machine {
key "name";
leaf "name" {
type string;
}
}
and in data tree:
"machine" : [
{ "name": "a" },
{ "name": "b" },
{ "name": "c" }
]
I want to know if the following request conforming to RESTCONF?
GET /restconf/data/test/machine
This request is expected to return all the list instances.
I have this question because I don't have a clear understanding of the words from RESTCONF. In RESTCONF 3.5.3,
If a data node in the path expression is a YANG list node, then the key values for the list (if any) MUST be encoded according to the following rules:
o The key leaf values for a data resource representing a YANG list MUST be encoded using one path segment [RFC3986].
o If there is only one key leaf value, the path segment is constructed by having the list name, followed by an "=" character, followed by the single key leaf value.
The (if any)
mean which one of the following two meanings? (the key
statement is not a must for a non-configuration list
. So there are keyed lists
and non-keyed lists
.)
Users are free to specify key values for keyed lists. The
(if any)
is about "if the key values are specified." If they specify then the key values MUST follow the rules about the key values. If they don't specify then you don't have to follow the rules about key values. Take my YANG definitions for example, these two requests are both correct:GET /restconf/data/test/machine // get all list instances GET /restconf/data/test/machine=a // get the list instance keyed "a"
Users have to specify key values for keyed lists. The
(if any)
is about "if the list is keyed or not." In this understanding, there will be:GET /restconf/data/test/machine // wrong request, can't get all list instanecs GET /restconf/data/test/machine=a // ok, get the list instance keyed "a"
The second understanding is from the similar words in the same section for leaf-lists:
If a data node in the path expression is a YANG leaf-list node, then the leaf-list value MUST be encoded according to the following rules:
o The identifier for the leaf-list MUST be encoded using one path segment [RFC3986].
o The path segment is constructed by having the leaf-list name, followed by an "=" character, followed by the leaf-list value (e.g., /restconf/data/top-leaflist=fred).
The words for leaf-lists don't have (if any)
, so you cannot use a URL like /restconf/data/top-leaflist
. You have to use =fred
to specify a leaf-list instance. So If leaf-list instances cannot be retrieved as a whole, why list instances can be retrieved as a whole (in understanding 1)? A leaf-list instance and a list instance are both a data resource, they are equivalent in concept.
Thanks,