cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1715
Views
5
Helpful
2
Replies

Display xml format as json while getting NSO Rest API-GET request

schallagalla
Level 1
Level 1

Dear Team,

When a get request is raised using nso rest api to display operational data, it will return the xml format. From CLI, it will display as json aswell. is there any way to get the output as json data format using rest. 

Ex: Below is the get request to show  services, can we get this response in json format? it is required to display data in UI. i have just taken the below example to define the problem statement.

 

GET req:

To display the service information :

http://localhost:8080/api/running/vlan-service

Response:

<collection xmlns:y="http://tail-f.com/ns/rest">
<vlan-service xmlns="http://com/vlan">
<device>ios_1</device>
<interface-name>Vlan</interface-name>
<interface-id>2</interface-id>
<description>Vlan interface</description>
</vlan-service>
<vlan-service xmlns="http://com/vlan">
<device>ios_0</device>
<interface-name>Vlan</interface-name>
<interface-id>1</interface-id>
<description>Vlan interface</description>
</vlan-service>
</collection>

2 Replies 2

tcragg1
Cisco Employee
Cisco Employee

You can make NSO respond with JSON to API requests using HTTP headers in the request. If you add an "Accept" HTTP header to the API request with a value of "application/vnd.yang.collection+json, application/vnd.yang.data+json" NSO should then return the same data in JSON format.

rogaglia
Cisco Employee
Cisco Employee

Hi,

I should also add that you should avoid using the "legacy-REST" API that you are using and move to the "standard-REST-RESTCONF" API as it is the current best practice.

 

Example GET RESTCONF call with Json output:

curl -X GET \
http://localhost:8080/restconf/data/tailf-ncs:java-vm \
-H 'Accept: application/yang-data+json' \
-H 'Authorization: Basic YWRtaW46YWRtaW4='

 

Where please pay attention that "tailf-ncs" is the name of the YANG module (and not its prefix) when you change namespaces in your query