cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
889
Views
2
Helpful
3
Replies

REST call filtering

Andre Gustavo Albuquerque
Cisco Employee
Cisco Employee

Hi,

I want to filter the result of a REST GET call to suppress some containers in the output.

Consider the YANG model below as example:

container networks {

  list network {

    key name;

    leaf name {

      type string;

    }

    container test1 {

     ...content suppressed for brevity...

    }

    container test2 {

     ...content suppressed for brevity...

    }

  }

}

My question is how to fetch all networks and displaying only the content from the container test1, suppressing others (e.g.: test2)?

Thanks in advance

1 Accepted Solution

Accepted Solutions

alam.bilal
Cisco Employee
Cisco Employee

Here is an example (I haven't tested it for your model, so you may need to tweak):

URL: http://localhost:8080/api/query

HTTP Method: POST

Payload:

<start-query xmlns="http://tail-f.com/ns/tailf-rest-query">

<foreach>

/networks/network

</foreach>

<select>

<label>test1</label>

<expression>test1</expression>

<result-type>inline</result-type> <== inline as we want a sub-tree

</select>

</start-query>

Response:

<start-query-result>

<query-handle>2</query-handle> <== Note the handle returned

</start-query-result>

To Fetch Result:

URL: http://localhost:8080/api/query

HTTP Method: POST

Payload:

<fetch-query-result xmlns="http://tail-f.com/ns/tailf-rest-query">

<query-handle>2</query-handle> <== supply back the previously returned handle

</fetch-query-result>

Response:

View solution in original post

3 Replies 3

alam.bilal
Cisco Employee
Cisco Employee

Hi There,

Take a look at the Query API (nso_northbound.pdf). It allows for filtering and selecting the nodes to be retrieved.

Thanks.

alam.bilal
Cisco Employee
Cisco Employee

Here is an example (I haven't tested it for your model, so you may need to tweak):

URL: http://localhost:8080/api/query

HTTP Method: POST

Payload:

<start-query xmlns="http://tail-f.com/ns/tailf-rest-query">

<foreach>

/networks/network

</foreach>

<select>

<label>test1</label>

<expression>test1</expression>

<result-type>inline</result-type> <== inline as we want a sub-tree

</select>

</start-query>

Response:

<start-query-result>

<query-handle>2</query-handle> <== Note the handle returned

</start-query-result>

To Fetch Result:

URL: http://localhost:8080/api/query

HTTP Method: POST

Payload:

<fetch-query-result xmlns="http://tail-f.com/ns/tailf-rest-query">

<query-handle>2</query-handle> <== supply back the previously returned handle

</fetch-query-result>

Response:

Thank you. I will try it.