Let’s go with a concrete example such as the rest/basic example in the ConfD example set.
If I perform a query call with the /dhcp/subnet list, I would get the following results:
$curl -i --cookie sessionid=sessJ/eO0txRa6CqxPV5NtpqYA== -X POST -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0", "id": 1,
"method": "query",
"params": { "th": 1,
"xpath_expr": "/dhcp:dhcp/dhcp:subnet",
"result_as": "keypath-value"} }' http://127.0.0.1:8008/jsonrpc
HTTP/1.1 200 OK
Server:
Date: Thu, 17 Dec 2015 23:16:14 GMT
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Cache-Control: private, no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, s-maxage=0
Content-Length: 386
Content-Type: application/json
Vary: Accept-Encoding
{"jsonrpc":"2.0","result":{"current_position":1,"total_number_of_results":2,"number_of_results":2,"number_of_elements_per_result":1,"results":[[{"keypath":"/dhcp:dhcp/subnet{10.254.239.0/27}","value":"10.254.239.0/2710.254.239.1010.254.239.20rtr-239-0-1.example.orgrtr-239-0-2.example.org1200"}],[{"keypath":"/dhcp:dhcp/subnet{10.254.240.0/27}","value":"10.254.240.0/276400"}]]},"id":1}+ echo '\n'
$ make cli
$CONFD_DIR/bin/confd_cli --user=admin --groups=admin \
--interactive || echo Exit
admin connected from 127.0.0.1 using console on WAITAI-M-K092
admin@WAITAI-M-K092> show configuration dhcp
Possible completions:
default-lease-time max-lease-time shared-networks subnet
admin@WAITAI-M-K092> show configuration dhcp subnet
subnet 10.254.239.0/27 {
range {
dynamic-bootp;
low 10.254.239.10;
high 10.254.239.20;
}
dhcp-options {
router [ rtr-239-0-1.example.org rtr-239-0-2.example.org ];
}
max-lease-time 1200;
}
subnet 10.254.240.0/27 {
max-lease-time 6400;
}
[ok][2015-12-17 15:17:57]
I have extracted the query results from the above json-rpc response and added my own formatting to make it easier to read as follows:
[ [{
“keypath”:"/dhcp:dhcp/subnet{10.254.239.0/27}",
“value”:“10.254.239.0/2710.254.239.1010.254.239.20
rtr-239-0-1.example.orgrtr-239-0-2.example.org1200
“}],
[{
“keypath”:”/dhcp:dhcp/subnet{10.254.240.0/27}”,
“value”:"10.254.240.0/276400
"}] ]
The results match the configuration data as shown through CLI. You will need to do some parsing to get at the leaf values.
If you add in the selection parameter for the leaf nodes, then you get the following:
$curl -i --cookie sessionid=sessG+QVr8j8o/fHnNyAk/z2Lg== -X POST -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0", "id": 1,
"method": "query",
"params": { "th": 1,
"xpath_expr": "/dhcp:dhcp",
"selection": ["max-lease-time", "default-lease-time"],
"result_as": "keypath-value"} }' http://127.0.0.1:8008/jsonrpc
HTTP/1.1 200 OK
Server:
Date: Thu, 17 Dec 2015 23:51:10 GMT
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Cache-Control: private, no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, s-maxage=0
Content-Length: 267
Content-Type: application/json
Vary: Accept-Encoding
{"jsonrpc":"2.0","result":{"current_position":1,"total_number_of_results":1,"number_of_results":1,"number_of_elements_per_result":2,"results":[[{"keypath":"/dhcp:dhcp/max-lease-time","value":"6400"},{"keypath":"/dhcp:dhcp/default-lease-time","value":"500"}]]},"id":1}+ echo '\n'