Describe Characteristics of REST
Describe Characteristics of REST
In this blog post, we will discuss REST-based APIs. We will also demonstrate how to use such APIs
with step-by-step scenarios using a Cisco virtual router running on the ESXi platform.
This article aims to help CCNA candidates in preparing for the following exam topic:
6.5 Describe characteristics of REST-based APIs (CRUD, HTTP verbs, and data encoding)
RESTful API
REST defines a set of architectural guidelines that were defined by Roy Fielding in his dissertation.
REST is not a protocol and doesn’t provide specific implementation details. For example, it doesn’t
mandate the use of HTTP, which is, however, is most often used and often associated with REST
APIs.
REST defines a set of constraints that must be met for a web service to be considered RESTful. The
full list of constraints is:
Create
Read
Update
Delete
HTTP request methods, also called verbs, can be mapped to CRUD operations. For example, in an
HTTP-based RESTful API, a client can change the parameters of a network interface by using the
HTTP PATCH method. We will show how it can be done in the example section.
HTTP GET method corresponds to Read operation. The server responds with a representation of a
resource identified by URI.
HTTP POST verb Creates a child or subordinate to resource specified in URI.
HTTP PUT maps to both Update and Create operations. If a resource specified in the PUT request
exists on the server, it should be replaced with the one in the request. If the resource doesn’t exist,
PUT can create it.
HTTP PATCH verb can also perform the Update operation. PATCH contains instructions on how to
update a resource, while PUT contains a modified copy of a resource.
HTTP DELETE maps to Delete operation.
REST API Example: CSR1000v
Let’s apply concepts from the previous section to practice. The next few sections will show how to
perform each of CRUD operations with REST-like API provided by Cisco IOS-XE routers.
This API is based on RESTCONF. It can return the representation of resources in XML or JSON
formats. RESTCONF uses YANG, which is modeling language describing a router’s configuration
and operation states.
Both RESTCONF and YANG are described in RFCs:
interface GigabitEthernet1
ip address 192.168.7.4 255.255.255.0
no shutdown
aaa new-model
aaa authentication login default local
aaa authorization exec default local
username admin secret ciscocisco
username admin privilege 15
enable secret ciscocisco
ip http server
ip http authentication local
ip http secure-server
restconf
Refer for details to the Cisco configuration guide, which is available via this URL.
Postman Client Setup
We will use free tier features of software called Postman (https://www.postman.com/).
Postman helps with testing and discovery of API prior to writing automation programs. The
automation scripts can be written using programming languages, such as Python with requests
library.
Download the software for the platform of your choice. We use the Windows version of Postman in
the next examples and the screenshots.
Start Postman and disable SSL certificate validation, as we are going to use the router’s IP address
and self-signed certificate in our examples:
Fig
ure 1. Postman – Disable SSL Certificate Verification
Figure 2. REST
API READ
The next figure shows the sequence of steps creating the request in Postman that returns the list of
interfaces of the router. The username and password values must match ones configured on the
router.
In this example, the URL of https://192.168.7.4/restconf/data/Cisco-IOS-XE-
native:native/interface/ consists of the following components:
Fig
ure 3. Postman –GET Request Parameters
The result of the request is shown in the next screenshot. The server replied back with a 200 OK
message and a representation of its interfaces in XML format.
Fig
ure 4. Postman – Read list of the Router’s Interfaces in XML Format
To switch to JSON we can adjust the request by modifying Headers as shown in Figure 5. Accept
key is set to value of application/yang-data+json. The response looks very similar to the one in
Figure 4, as both XML and JSON represent the same resource – a list of interfaces of the router.
Fig
ure 5. Postman – Read list of the Router’s Interfaces in JSON Format
Fig
ure 6. Cisco IOS-XE REST API Create an Interface with HTTP POST
Figure 7 shows Postman configuration for this request.
Fig
ure 7. Postman – Create an Interface with HTTP POST
The listing below shows JSON representation of the interface:
{
"Cisco-IOS-XE-native:Loopback": {
"name": "1",
"description": "Test",
"ip": {
"address": {
"primary": {
"address": "192.168.8.1",
"mask": "255.255.255.255"
}
}
}
}
}
The router has its configuration updated with new Loopback1 interface:
Fig
ure 8. REST API Update with HTTP PATCH
Postman query configuration steps are shown in Figure 9. Note that authorization settings must be
set in the same way as done in the HTTP GET example.
Fig
ure 9. Postman – Updating Interface Description using HTTP PATCH
The listing below shows JSON representation of the description change:
{
"Cisco-IOS-XE-native:GigabitEthernet": {
"description": "Very Important Interface",
}
}
Fig
ure 9. Postman – Deleting Interface with HTTP DELETE
And the listing below demonstrates that the interface doesn’t exist anymore:
Self-Test Questions
What is REST and RESTful API?
REpresentational State Transfer (REST) is an architectural style that defines a set of constraints to
create APIs. RESTful API is an API that meets all the constraints.