cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements

Community Helping Community

116
Views
2
Helpful
3
Replies

REST call filtering

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

Everyone's tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Cisco Employee

Re: REST call filtering

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
Cisco Employee

Re: REST call filtering

Hi There,

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

Thanks.

Cisco Employee

Re: REST call filtering

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

Re: REST call filtering

Thank you. I will try it.