Junos® OS
REST API Guide
Published
2024-06-22
Juniper Networks, Inc.
1133 Innovaon Way
Sunnyvale, California 94089
USA
408-745-2000
www.juniper.net
Juniper Networks, the Juniper Networks logo, Juniper, and Junos are registered trademarks of Juniper Networks, Inc.
in the United States and other countries. All other trademarks, service marks, registered marks, or registered service
marks are the property of their respecve owners.
Juniper Networks assumes no responsibility for any inaccuracies in this document. Juniper Networks reserves the right
to change, modify, transfer, or otherwise revise this publicaon without noce.
Junos® OS REST API Guide
Copyright © 2024 Juniper Networks, Inc. All rights reserved.
The informaon in this document is current as of the date on the tle page.
YEAR 2000 NOTICE
Juniper Networks hardware and soware products are Year 2000 compliant. Junos OS has no known me-related
limitaons through the year 2038. However, the NTP applicaon is known to have some diculty in the year 2036.
END USER LICENSE AGREEMENT
The Juniper Networks product that is the subject of this technical documentaon consists of (or is intended for use
with) Juniper Networks soware. Use of such soware is subject to the terms and condions of the End User License
Agreement ("EULA") posted at hps://support.juniper.net/support/eula/. By downloading, installing or using such
soware, you agree to the terms and condions of that EULA.
ii
Table of Contents
About This Guide | iv
1
Overview
Understanding the REST API | 2
2
Conguring and Using the REST API
Conguring the REST API | 6
Example: Conguring the REST API | 7
Requirements | 8
Overview | 8
Conguraon | 8
Vericaon | 11
Example: Using the REST API Explorer | 13
Requirements | 13
Overview | 13
Conguraon | 14
Subming a GET Request to the REST API | 24
Subming a POST Request to the REST API | 27
3
Conguraon Statements and Operaonal Commands
Junos CLI Reference Overview | 32
iii
About This Guide
The Junos OS REST API is a Representaonal State Transfer (REST) interface that enables you to
securely connect to Junos OS devices, execute remote procedure calls, use a REST API Explorer
graphical user interface enabling you to conveniently experiment with any of the REST APIs, and use a
variety of formang and display opons including JavaScript Object Notaon (JSON).
iv
1
CHAPTER
Overview
Understanding the REST API | 2
Understanding the REST API
The REST API is a Representaonal State Transfer (REST) interface that enables you to securely connect
to Juniper Networks Junos operang system (Junos OS) devices, execute remote procedure calls (rpc
commands), use a REST API Explorer GUI enabling you to conveniently experiment with any of the REST
APIs, and use a variety of formang and display opons, including JavaScript Object Notaon (JSON).
The REST API can be congured on Junos OS devices using commands available under the [edit system
services rest] hierarchy level. Once congured, the REST API becomes available as the rest service, a
REST-based interface that enables you to submit rpc commands to the device from a remote locaon,
and supports GET and POST requests. With the REST API you can:
Use GET requests to submit rpc commands.
Use POST requests to submit informaon via rpc commands.
Retrieve conguraon informaon in XML, ASCII (plain text), or JSON.
Retrieve operaonal data in XML, ASCII, or JSON.
At the [edit system services rest] hierarchy level, you can congure and secure the REST API service on a
Junos OS device; set up IP addresses, port numbers, server cercates, control parameters, and trace
opons; and enable a REST API explorer tool that enables you to try the REST APIs using a convenient
GUI.
The following CLI display opons are available:
A display json opon is added to the
| (pipe)
command. For example, the CLI command show interfaces
| display json displays the interfaces in JSON notaon.
A format="json" opon is added to NETCONF server commands to return operaonal informaon in
JSON notaon.
NOTE: Starng in Junos OS Release 17.3R1, OpenCong supports the operaonal state emied
by daemons directly in JSON format in addion to XML format. To congure JSON compact
format, specify the following CLI command: set system export-format state-data json compact. This
CLI command converts XML format to compact JSON format. Else, it emits the JSON in non-
compact format.
NOTE: The REST API incoming request payload size cannot exceed 1174KB.
2
Workaround: Chunk the incoming REST API requests into a smaller size.
The REST API supports HTTP Basic Authencaon, and all requests require a base64-encoded
username and password included in the Authorizaon header. Both HTTP and HTTPS support are
available:
You can use HTTP to exchange content using clear text if you do not need a secure connecon.
We recommend that you use HTTPS to exchange encrypted content using one of the available cipher
suites. You can congure the REST API to require server authencaon without client authencaon,
or you can congure mutual authencaon.
Once the REST API is congured on the device, new REST endpoints are available for execung either
single rpc commands via GET or POST requests, or execung mulple rpc commands via a single POST
request. See "Subming a GET Request to the REST API" on page 24 and "Subming a POST Request
to the REST API" on page 27 for more informaon.
The REST API also provides a GUI called the REST API Explorer, which allows you to easily and quickly
learn how to use the REST API. It is disabled by default, and can be enabled by specifying set system
services rest enable-explorer. To learn more about the REST API Explorer, see "Example: Using the REST
API Explorer" on page 13.
Change History Table
Feature support is determined by the plaorm and release you are using. Use Feature Explorer to
determine if a feature is supported on your plaorm.
Release
Descripon
17.3R1 Starng in Junos OS Release 17.3R1, OpenCong supports the operaonal state emied by daemons
directly in JSON format in addion to XML format. To congure JSON compact format, specify the
following CLI command: set system export-format state-data json compact. This CLI command converts
XML format to compact JSON format. Else, it emits the JSON in non-compact format.
RELATED DOCUMENTATION
Example: Using the REST API Explorer | 13
Conguring the REST API | 6
Subming a GET Request to the REST API | 24
Subming a POST Request to the REST API | 27
| (pipe)
Pipe ( | ) Filter Funcons in the Junos OS Command-Line Interface
3
Specifying the Output Format for Operaonal Informaon Requests in a NETCONF Session
4
2
CHAPTER
Conguring and Using the REST API
Conguring the REST API | 6
Example: Conguring the REST API | 7
Example: Using the REST API Explorer | 13
Subming a GET Request to the REST API | 24
Subming a POST Request to the REST API | 27
Conguring the REST API
The REST API can be congured on Junos OS devices using commands available under the [edit system
services rest] hierarchy level. Once congured, the REST API becomes available as the rest service, a
REST-based interface that enables you to submit rpc commands to the device from a remote locaon,
and supports GET and POST requests.
To enable the REST API on your device, you need to congure:
Control parameters— These allow you to oponally specify permied source IP addresses and
connecon limits common to both HTTP and HTTPS connecons.
REST API Explorer— The REST API provides a GUI called the REST API Explorer, which allows you to
easily and quickly learn how to use the REST API. It is disabled by default, and can be enabled by
specifying set system services rest enable-explorer. To learn more about the REST API Explorer, see
"Example: Using the REST API Explorer" on page 13.
HTTP access— You can specify a list of addresses and TCP ports for incoming connecons. HTTP
connecons are not secure because they exchange credenals and data in clear text, so we
recommend using HTTPS.
HTTPS access (
recommended
)— You can specify a list of addresses and TCP ports for incoming
connecons, a list of preferred cipher suites, transport layer security (TLS) mutual authencaon, and
server cercates. HTTPS connecons are secure, encrypng both credenals and informaon.
Trace opons— You can enable tracing for lighpd, User Interface Script Environment (juise), or both.
Trace informaon for lighpd is stored at /var/chroot/rest-api/var/log/lighpd, and trace
informaon for juise is stored at /var/chroot/rest-api/var/log/juise. Tracing is disabled by default.
To congure the oponal control parameters for sengs common to both HTTP and HTTPS
connecons:
1. Specify set system services rest control allowed-sources [
value-list
] to set the permied IP addresses
for both HTTP and HTTPS connecons. Use spaces as delimiters between values.
2. Specify set system services rest control connection-limit
limit
to set the maximum number of allowed
simultaneous connecons for both HTTP and HTTPS connecons. You can assign a value from 1
through 1024 (the default is 64).
To congure HTTP access:
1. Specify set system services rest http addresses [
addresses
] to set the addresses on which the server
listens for incoming HTTP connecons.
2.
Specify set system services rest http port
port-number
to set the TCP port for incoming HTTP
connecons. You can assign a value from 1024 through 65535 (the default is 3000).
6
To congure HTTPS access:
1. Specify set system services rest https addresses [
addresses
] to set the addresses on which the server
listens for incoming HTTPS connecons.
2. Specify set system services rest https port
port-number
to set the TCP port for incoming HTTPS
connecons. You can assign a value from 1024 through 65535 (the default is 3443).
3. Specify set system services rest https cipher-list[
cipher-1 cipher-2 cipher-3 ...
] to congure the set of
cipher suites the SSH server can use to perform encrypon and decrypon funcons.
4. Specify set system services rest https server-certificate
local-certificate-identifier
to congure the
server cercate. See request security pki generate-cercate-request for informaon about
creang local cercates.
5. You can congure the REST API to require server authencaon without client authencaon, or
you can congure TLS mutual authencaon on both the server and client by specifying set system
services rest https mutual-authentication certificate-authority
certificate-authority-profile-name
.
To congure trace opons for lighpd, juise, or both, specify set system services rest traceoptions flag
flag
. Set
flag
to lighttpd, juise, or all. When you specify the trace opons, the command overwrites any
previous trace opon sengs.
RELATED DOCUMENTATION
rest
Understanding the REST API | 2
Example: Using the REST API Explorer | 13
Example: Conguring the REST API
IN THIS SECTION
Requirements | 8
Overview | 8
Conguraon | 8
Vericaon | 11
7
This example demonstrates how to congure the REST API on a Junos OS device.
Requirements
A roung, switching, or security device running Junos OS Release 14.2 or later is required.
Overview
This example congures the REST API on a Juniper Networks M10i Mulservice Edge Router. The
example congures both HTTP and HTTPS access, with both lighpd and juise tracing.
Conguraon
IN THIS SECTION
CLI Quick Conguraon | 8
Conguring the REST API | 9
Results | 11
CLI Quick Conguraon
To quickly congure this example, copy the following commands, paste them in a text le, remove any
line breaks, change any details necessary to match your network conguraon, copy and paste the
commands into the CLI at the [edit] hierarchy level, and then enter commit from conguraon mode.
set system services rest control allowed-sources [192.0.2.0 198.51.100.0]
set system services rest control connection-limit 100
set system services rest http port 3000
set system services rest http addresses [203.0.113.0 203.0.113.1]
set system services rest https port 3443
set system services rest https addresses [203.0.113.2 203.0.113.3]
set system services rest https server-certificate testcert
8
set system services rest https cipher-list rsa-with-3des-ede-cbc-sha
set system services rest https mutual-authentication certificate-authority testca
set system services rest traceoptions flag all
set system services rest enable-explorer
Conguring the REST API
Step-by-Step Procedure
To congure the REST API:
1. Specify allowed IP addresses for incoming HTTP and HTTPS connecons.
[edit]
user@R1# set system services rest control allowed-sources [192.0.2.0 198.51.100.0]
2. Specify the maximum number of allowed connecons over both HTTP and HTTPS.
[edit]
user@R1# set system services rest control connection-limit 100
3. Set the TCP port for incoming HTTP connecons.
[edit]
user@R1# set system services rest http port 3000
4. Set the addresses on which the server listens for incoming HTTP connecons.
[edit]
user@R1# set system services rest http addresses [203.0.113.0 203.0.113.1]
5. Set the TCP port for incoming HTTPS connecons.
[edit]
user@R1# set system services rest https port 3443
9
6. Set the addresses on which the server listens for incoming HTTPS connecons.
[edit]
user@R1# set system services rest https addresses [203.0.113.2 203.0.113.3]
7. Set the server cercate.
[edit]
user@R1# set system services rest https server-certificate testcert
8. Congure the set of ciphers the server can use to perform encrypon and decrypon funcons.
[edit]
user@R1# set system services rest https cipher-list rsa-with-3des-ede-cbc-sha
9. (Oponal) Set up TLS mutual authencaon on both the server and client with a cercate.
[edit]
user@R1# set system services rest https mutual-authentication certificate-authority testca
10. (Oponal) Congure trace opons for lighpd, juise, or both.
[edit]
user@R1# set system services rest traceoptions flag all
11. (Oponal) Enable the REST API Explorer.
[edit]
user@R1# set system services rest enable-explorer
12. Commit the conguraon.
[edit]
user@R1# commit and-quit
10
Results
system {
services {
rest {
control {
allowed-sources [ 192.0.2.0 198.51.100.0 ];
connection-limit 100;
}
enable-explorer;
http {
addresses [ 203.0.113.0 203.0.113.1 ];
port 3000;
}
https {
port 3443;
addresses [ 203.0.113.2 203.0.113.3 ];
server-certificate testcert;
cipher-list rsa-with-3des-ede-cbc-sha;
mutual-authentication {
certificate-authority testca;
}
}
traceoptions {
flag all;
}
}
}
}
Vericaon
IN THIS SECTION
Verifying REST API Conguraon | 12
11
Verifying REST API Conguraon
Purpose
Conrm that the REST API conguraon is working properly on the device.
Acon
Display the REST API conguraon by issuing the show configuration system services rest operaonal mode
command.
user@R1> show configuration system services rest
http {
port 3000;
addresses [ 203.0.113.0 203.0.113.1 ];
}
https {
port 3443;
addresses [ 203.0.113.2 203.0.113.3 ];
server-certificate testcert;
cipher-list rsa-with-3des-ede-cbc-sha;
mutual-authentication {
certificate-authority testca;
}
}
control {
allowed-sources [ 192.0.2.0 198.51.100.0 ];
connection-limit 100;
}
traceoptions {
flag all;
}
enable-explorer;
Meaning
This example congured both HTTP and HTTPS access on a Juniper Networks M10i Mulservice Edge
Router. For HTTP access, the device listens on port 3000 and permits trac from IP addresses
192.0.2.0, 198.51.100.0, 203.0.113.0, and 203.0.113.1. For a more secure connecon, HTTPS access
was congured with mutual authencaon, using port 3443 and allowed IP addresses of 192.0.2.0,
198.51.100.0, 203.0.113.2, and 203.0.113.3. A connecon limit of 100 has been congured for both
12
HTTP and HTTPS, and both juise and lighpd tracing has been enabled. By default, the REST API
Explorer is disabled (see "Example: Using the REST API Explorer" on page 13).
RELATED DOCUMENTATION
Understanding the REST API | 2
Conguring the REST API | 6
Example: Using the REST API Explorer | 13
Example: Using the REST API Explorer
IN THIS SECTION
Requirements | 13
Overview | 13
Conguraon | 14
This example demonstrates how to oponally use the REST API Explorer on a Junos OS device on which
the REST API has been congured.
Requirements
An M Series, MX Series, T Series, or PTX Series device running Junos OS Release 14.2 or later is
required.
Overview
The REST API Explorer allows you to conveniently test out single or mulple RPC calls. Its GUI provides
you with opons to select the HTTP method (GET or POST), the required output format (XML, JSON, or
plain text), the RPC URL, the input data type when using POST requests (XML or plain text), and an exit-
13
on-error condion. When you submit the request, the REST API Explorer displays the request header,
response header, response body, and equivalent cURL request, all of which are useful to your
development eorts.
Conguraon
IN THIS SECTION
Enabling the REST API Explorer | 14
Opening the REST API Explorer | 15
Execung a Single RPC Using an HTTP GET Request | 16
Execung a Single RPC Using an HTTP POST Request | 17
Execung Mulple RPCs | 20
Viewing Error Messages | 21
To use the REST API Explorer on any device on which the REST API has been congured, perform these
tasks:
Enabling the REST API Explorer
Step-by-Step Procedure
To enable the REST API Explorer:
1. Congure the REST API on the device.
See "Conguring the REST API" on page 6 and "Example: Conguring the REST API" on page 7 for
informaon and examples.
2. Check whether the REST API Explorer is enabled.
14
Use the show command to see if enable-explorer; appears in the REST API conguraon. If it appears,
the REST API Explorer has been enabled. If it does not appear, you must enable the REST API
Explorer.
[edit]
user@R1# show system services rest
http;
traceoptions {
flag all;
}
enable-explorer;
3. Enable the REST API Explorer if necessary.
Use the set command to ensure that enable-explorer; appears in the REST API conguraon.
[edit]
user@R1# set system services rest enable-explorer
Opening the REST API Explorer
Step-by-Step Procedure
To open the REST API Explorer:
Ensure that the REST API Explorer is enabled, open a browser, and go to the following URL:
scheme://device-name:port (for example, hps://mydevice:3000).
15
Execung a Single RPC Using an HTTP GET Request
Step-by-Step Procedure
To execute a single RPC using an HTTP GET Request:
1. In the HTTP method drop-down list, select GET.
2. Enter the RPC URL endpoint.
For example, type /rpc/get-software-information.
3. Enter your username and password.
4. Click Submit.
In this example, the default output format, XML, is returned in the Response Body:
16
Execung a Single RPC Using an HTTP POST Request
Step-by-Step Procedure
To execute a single RPC using an HTTP POST Request:
1. In the HTTP method drop-down list, select POST.
17
2. In the Required output format drop-down list, select JSON.
3. Enter this RPC URL endpoint: /rpc/get-software-information.
4. Enter your username and password.
5. Enter the XML-formaed request in the Request body text area.
For example:
<brief/>
6. Click Submit.
In this example, the JSON output format is returned in the Response Body:
7. If you prefer a dierent output format, select one of the available choices in the Required output
format drop-down list.
18
For example, you could select Plain text. When you click Submit, you will see plain text in the
Response Body:
19
Similarly, if you select XML in the Required output format drop-down list, the response body will
contain XML-formaed informaon:
Execung Mulple RPCs
Step-by-Step Procedure
To execute mulple RPCs:
1. In the HTTP method drop-down list, select POST.
This is always required when execung mulple RPCs.
2. To set a condional exit in the event of an error, select the Exit on error checkbox.
3. Select an output format in the Required output format drop-down list.
For example, you could select JSON.
4. This RPC URL endpoint will automacally populate: /rpc?exit-on-error=1.
20
5. Enter your username and password.
6. Enter the XML-formaed request in the Request body text area.
For example:
<get-software-information />
<get-interface-information />
7. Click Submit.
In this example, the JSON output format is returned in the Response Body:
Viewing Error Messages
Step-by-Step Procedure
When execung mulple RPCs, an error might occur. If you select the Exit on error checkbox, an error
message will appear in the output if an error occurs.
To view error messages:
1. In the HTTP method drop-down list, select POST.
This is always required when execung mulple RPCs.
2. To set a condional exit in the event of an error, select the Exit on error checkbox.
3. Select an output format in the Required output format drop-down list.
21
For example, you could select JSON.
4. This RPC URL endpoint will automacally populate: /rpc?exit-on-error=1.
5. Enter your username and password.
6. Enter the XML-formaed request containing an error in the Request body text area.
For example:
<get-software-information />
<get-unknown-rpc />
<get-interface-information />
7. Click Submit.
In this example, the JSON output format is returned in the Response Body, and you can see an XML-
formaed error message at the end of the Response Body:
22
8. If you do not select the Exit on error checkbox, an error message will appear in the Response Body if
an error occurs.
Execuon will connue aer the error is processed, and the results will also be included in the
Response Body:
23
RELATED DOCUMENTATION
Understanding the REST API | 2
Conguring the REST API | 6
Subming a GET Request to the REST API
For an rpc command, the general format of the endpoints is:
scheme://device-name:port/rpc/method[@attributes]/params
24
scheme: http or https
method: The name of any Junos OS rpc command. The method name is idencal to the tag element. For
more informaon, see the
Junos XML API Operaonal Developer Reference
.
params: Oponal parameter values (name[=value]).
To authencate your request, submit the base64-encoded username and password included in the
Authorizaon header:
curl -u "username:password" http://device-name:port/rpc/get-interface-information
To specify rpc data as a query string in the URI for GET requests, you can use a ? following the URI with
the & delimiter separang mulple arguments, or use the / delimiter, as shown in these equivalent cURL
calls:
For example:
curl -u "username:password" http://device-name:port/rpc/get-interface-information?interface-name=cbp0&snmp-
index=1
curl -u "username:password" http://device-name:port/rpc/get-interface-information/interface-name=cbp0/snmp-
index=1
HTTP Accept headers can be used to specify the return format using one of the following Content-Type
values:
applicaon/xml (the default)
applicaon/json
text/plain
text/html
For example, the following cURL call species an output format of JSON:
curl -u "username:password" http://device-name:port/rpc/get-interface-information?interface-
name=cbp0 –header "Accept: application/json"
You can also specify the output format using the oponal format parameter.
25
For example, the <get-software-information> tag element retrieves soware process revision levels. The
following HTTPS GET request executes this command and retrieves the results in JSON format:
https://device-name:3000/rpc/get-software-information@format=json
The following Python program uses the REST interface to execute the get-route-engine-information RPC,
extracts the data from the response, and plots a graph of the CPU load average:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import requests
temp_y = 1
def update_line(num, data, line):
if num == 0:
return line,
global temp_y
x_data.append(num)
if num is not 0 and num%8 == 1:
r = requests.get('scheme://device:port/rpc/get-route-engine-information@format=json',
auth=('username', 'password'))
if r: temp_y = r.json()["route-engine-information"][0]["route-engine"][0]["load-average-
one"][0]["data"]
y_data.append(temp_y)
line.set_data(x_data, y_data)
return line,
fig1 = plt.figure()
x_data = []
y_data = []
l, = plt.plot([], [])
plt.xlim(0, 80)
plt.ylim(0, 1.5)
plt.xlabel('Time in seconds')
plt.ylabel('CPU utilization (load average)')
plt.title('REST-API test')
line_ani = animation.FuncAnimation(fig1, update_line, 80, fargs=(0, l), interval=1000, blit=True)
plt.show()
26
RELATED DOCUMENTATION
Understanding the REST API | 2
Conguring the REST API | 6
Example: Using the REST API Explorer | 13
| (pipe)
Pipe ( | ) Filter Funcons in the Junos OS Command-Line Interface
Specifying the Output Format for Operaonal Informaon Requests in a NETCONF Session
Subming a POST Request to the REST API
Use an HTTP POST request to send single or mulple RPC requests to the REST API. You can use the
POST request to do device conguraon.
For a single rpc command, the general format of the endpoints is:
scheme://device-name:port/rpc/method[@attributes]/params
scheme: http or https
method: The name of any Junos OS rpc command. The method name is idencal to the tag element. For
more informaon, see the Junos XML Protocol Operaons, Processing Instrucons, and Response
Tags in the Junos XML Management Protocol Developer Guide and the
Junos XML API Operaonal
Developer Reference
.
params: Oponal parameter values (name[=value]).
27
To authencate your request, submit the base64-encoded username and password included in the
Authorizaon header:
curl -u "username:password" http://device-name:port/rpc/get-interface-information
To specify rpc data as a query string in the URI for POST requests, submit the query data in the POST
body. In such cases you can specify the Content-Type as text/plain or application/xml, as shown in these
equivalent cURL calls:
curl -u "username:password" http://device-name:port/rpc/get-interface-information --header
"Content-Type: text/plain" –d "interface-name=cbp0"
curl -u "username:password" http://device-name:port/rpc/get-interface-information --header
"Content-Type: application/xml" –d "<interface-name>cbp0</interface-name>"
For both single and mulple RPC commands, HTTP Accept headers can be used to specify the return
format using one of the following Content-Type values:
applicaon/xml (the default)
applicaon/json
text/plain
text/html
For example, the following cURL call species an output format of JSON:
curl -u "username:password" http://device-name:port/rpc -d <get-software-information /> –header
"Accept: application/json"
You can also specify the output format using the oponal format aribute:
curl -u "username:password" http://device-name:port/rpc -d "<get-software-information
format=application/json'/>"
NOTE: The default Content-Type for POST requests containing arguments in the body is
applicaon/xml. If you want to use any other content, such as a query string, you can specify a
Content-Type of text/plain. Specify the format aribute in conguraon commands.
28
When execung mulple rpc commands in a single request, the general format of the endpoint is:
scheme://device-name:port/rpc
The RPCs must be provided as XML data in the POST body. The Content-Type for the response is
mulpart/mixed, with boundary and subtype associated with the output from each RPC execuon. The
format specied in the Accept header is used as the output format for each of the RPCs if they are
missing a format aribute. If an Accept header is not specied and no format aribute is specied in a
given RPC, the default output format is XML. For example, to send a single HTTP request to execute the
RPCs get-software-information and get-interface-information, submit a POST request to /rpc with "Auth: Basic
<base64hash>", "Content-Type: application/xml". The POST body would contain:
<get-software-information/><get-interface-information/>
Here is a cURL call using this POST body:
curl -u "username:password" http://device-name:port/rpc -d "<get-software-information/><get-
interface-information/>"
The output from the request, containing XML as the default, would appear as follows:
HTTP/1.1 200 OK
Content-Type: multipart/mixed; boundary=fkj49sn38dcn3
Transfer-Encoding: chunked
Date: Thu, 20 Mar 2014 11:01:27 GMT
Server: lighttpd/1.4.32
--fkj49sn38dcn3
Content-Type: application/xml
<software-information>
<host-name>...</host-name>
...
</software-information>
--fkj49sn38dcn3
Content-Type: application/xml
<interface-information>
<physical-interface>...</physical-interface>
</interface-information>
--fkj49sn38dcn3--
29
You can also specify the output format for each of the elements in the POST body. For example, the
following request emits JSON for the get-interface-information RPC and plain text for the get-software-
information RPC:
curl -u "username:password" http://device-name:port/rpc
-d "<get-interface-information/><get-software-information format='text/plain'/>"
—header "Accept: application/json"
When execung mulple RPCs, if an error occurs, the default behavior is to ignore the error and
connue execuon. If you want to exit when the rst error is encountered, specify the stop-on-error ag
in the URI. For example, the following request congures the device and terminates if an error is
encountered:
curl -u "username:password" http://device-name:port/rpc?stop-on-error=1
-d "<lock-configuration/>
<load-configuration>
<configuration><system><hostname>foo</hostname></system></configuration>
</load-configuration>
<commit/>
<unlock-configuration/>"
RELATED DOCUMENTATION
Understanding the REST API | 2
| (pipe)
Pipe ( | ) Filter Funcons in the Junos OS Command-Line Interface
Specifying the Output Format for Operaonal Informaon Requests in a NETCONF Session
Conguring the REST API | 6
Example: Using the REST API Explorer | 13
30
3
CHAPTER
Conguraon Statements and
Operaonal Commands
Junos CLI Reference Overview | 32
Junos CLI Reference Overview
We've consolidated all Junos CLI commands and conguraon statements in one place. Learn about the
syntax and opons that make up the statements and commands and understand the contexts in which
you’ll use these CLI elements in your network conguraons and operaons.
Junos CLI Reference
Click the links to access Junos OS and Junos OS Evolved conguraon statement and command
summary topics.
Conguraon Statements
Operaonal Commands
32