Understanding the REST API
The REST API is a Representational State Transfer (REST) interface that enables you to
securely connect to Juniper Networks Junos operating 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
formatting and display options, including JavaScript Object Notation (JSON).
The REST API can be configured on Junos OS devices using commands available under the
[edit system services rest] hierarchy level. Once configured, 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
location, and supports GET and POST requests. With the REST API you can:
-
Use GET requests to submit
rpccommands. -
Use POST requests to submit information via
rpccommands. -
Retrieve configuration information in XML, ASCII (plain text), or JSON.
-
Retrieve operational data in XML, ASCII, or JSON.
At the [edit system services rest] hierarchy level, you can configure
and secure the REST API service on a Junos OS device; set up IP addresses, port numbers,
server certificates, control parameters, and trace options; and enable a REST API
explorer tool that enables you to try the REST APIs using a convenient GUI.
The following CLI display options are available:
-
A
display jsonoption is added to the | (pipe) command. For example, the CLI commandshow interfaces | display jsondisplays the interfaces in JSON notation. -
A
format="json"option is added to NETCONF server commands to return operational information in JSON notation.
The REST API incoming request payload size cannot exceed 1174KB.
Workaround: Chunk the incoming REST API requests into a smaller size.
The REST API supports HTTP Basic Authentication, and all requests require a base64-encoded username and password included in the Authorization 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 connection.
-
We recommend that you use HTTPS to exchange encrypted content using one of the available cipher suites. You can configure the REST API to require server authentication without client authentication, or you can configure mutual authentication.
Once the REST API is configured on the device, new REST endpoints are available for
executing either single rpc commands via GET or POST requests, or
executing multiple rpc commands via a single POST request. See Submitting a GET Request to the REST API and Submitting a POST Request to the REST API for more
information.
Junos OS supports emitting operational state data in compact JSON format. To emit the
JSON data in compact format, configure the json compact statement at
the [edit system export-format state-data] hierarchy level. Otherwise,
the device emits the JSON data in non-compact format by default.
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.
Change History Table
Feature support is determined by the platform and release you are using. Use Feature Explorer to determine if a feature is supported on your platform.
compact statement at the
[edit system export-format state-data json] hierarchy
level.