B.3.2. “depth”参数

depth”参数用于限制服务器为GET方法请求返回的子资源的级别数。

depth”参数在指定的目标资源级别开始计数级别,以便深度级别“1”仅包括目标资源级别本身。 深度级别“2”包括目标资源级别及其子节点。

此示例显示“depth”参数的不同值将如何影响用于检索顶层“jukebox”数据资源的回复内容。

示例1: depth=unbounded

要检索所有子资源,“depth”参数不存在或设置为默认值“unbounded”。

  1. GET /restconf/data/example-jukebox:jukebox?depth=unbounded HTTP/1.1
  2. Host: example.com
  3. Accept: application/yang-data+json

服务器可能会如下回应:

  1. HTTP/1.1 200 OK
  2. Date: Thu, 26 Jan 2017 20:56:30 GMT
  3. Server: example-server
  4. Cache-Control: no-cache
  5. Content-Type: application/yang-data+json
  6. {
  7. "example-jukebox:jukebox" : {
  8. "library" : {
  9. "artist" : [
  10. {
  11. "name" : "Foo Fighters",
  12. "album" : [
  13. {
  14. "name" : "Wasting Light",
  15. "genre" : "example-jukebox:alternative",
  16. "year" : 2011,
  17. "song" : [
  18. {
  19. "name" : "Wasting Light",
  20. "location" :
  21. "/media/foo/a7/wasting-light.mp3",
  22. "format" : "MP3",
  23. "length" : 286
  24. },
  25. {
  26. "name" : "Rope",
  27. "location" : "/media/foo/a7/rope.mp3",
  28. "format" : "MP3",
  29. "length" : 259
  30. }
  31. ]
  32. }
  33. ]
  34. }
  35. ]
  36. },
  37. "playlist" : [
  38. {
  39. "name" : "Foo-One",
  40. "description" : "example playlist 1",
  41. "song" : [
  42. {
  43. "index" : 1,
  44. "id" : "/example-jukebox:jukebox/library/artist[name='Foo Fighters']/album[name='Wasting Light']/song[name='Rope']"
  45. },
  46. {
  47. "index" : 2,
  48. "id" : "/example-jukebox:jukebox/library/artist[name='Foo Fighters']/album[name='Wasting Light']/song[name='Bridge Burning']"
  49. }
  50. ]
  51. }
  52. ],
  53. "player" : {
  54. "gap" : 0.5
  55. }
  56. }
  57. }

示例2: depth=1

要确定给定目标资源是否存在一个或多个资源实例,请使用值“1”。

  1. GET /restconf/data/example-jukebox:jukebox?depth=1 HTTP/1.1
  2. Host: example.com
  3. Accept: application/yang-data+json

服务器可能会如下回应:

  1. HTTP/1.1 200 OK
  2. Date: Thu, 26 Jan 2017 20:56:30 GMT
  3. Server: example-server
  4. Cache-Control: no-cache
  5. Content-Type: application/yang-data+json
  6. {
  7. "example-jukebox:jukebox" : {}
  8. }

示例2: depth=3

将深度级别限制为目标资源加两个子级资源层,使用值“3”。

  1. GET /restconf/data/example-jukebox:jukebox?depth=3 HTTP/1.1
  2. Host: example.com
  3. Accept: application/yang-data+json

服务器可能会如下回应:

  1. HTTP/1.1 200 OK
  2. Date: Thu, 26 Jan 2017 20:56:30 GMT
  3. Server: example-server
  4. Cache-Control: no-cache
  5. Content-Type: application/yang-data+json
  6. {
  7. "example-jukebox:jukebox" : {
  8. "library" : {
  9. "artist" : {}
  10. },
  11. "playlist" : [
  12. {
  13. "name" : "Foo-One",
  14. "description" : "example playlist 1",
  15. "song" : {}
  16. }
  17. ],
  18. "player" : {
  19. "gap" : 0.5
  20. }
  21. }
  22. }