08-06-2019 01:11 AM
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>
08-06-2019 02:26 AM
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.
08-08-2019 11:19 AM
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
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide