Network Automation Series: Part 2
REST is an architectural style for building an Application Programming Interface (API). REST is not based upon any protocol, however most all REST services leverage HTTP as the underlying protocol.
The purpose of RESTful service is to provide access to resources. A resource in object oriented programming parlance can be considered as an object and could contain references to other resources. A good high level description of REST from Wikipedia (2017):
“Representational state transfer (REST) or RESTful Web services are one way of providing interoperability between computer systems on the Internet. REST-compliant Web services allow requesting systems to access and manipulate textual representations of Web resources using a uniform and predefined set of stateless operations.”
This description introduces some key properties of REST, which are:
In general, a web service is a way for two systems to communicate through a defined interface. In the past 20 years, there have been two major types of Web Services – REST or SOAP. In the last 10 years, the REST approach has become increasingly popular.
HTTP(S) uses CRUD (Create, Read, Update, Delete) operations on the wire to request data. In the example below, our browser is issuing a GET operation to read the associated web page. The web server returns the associated data and an HTTP response to the client browser.
RESTful interfaces offer these same CRUD (Create, Read, Update, Delete) operations using HTTP(S). Browsers are replaced by software to interface with the RESTful service. The diagram below illustrates the same concept; however, browsers are replaced by software leveraging the REST API.
<METHOD/VERB> is one of the HTTP methods like:
<URI> is the URI of the resource on which the operation is to be performed
<AUTHENTICATION> Authentication credentials and Authentication type
<REQUEST HEADER> contains the metadata as a collection of key-value pairs of headers and their values. These settings contain information about the message and it sender like client type, the formats client supports, format type of the message body, cache settings for the response, and a lot more information.
<REQUEST BODY> This is the actual message content.
The server returns <response code>, which containers the status of the request. This response code is generally the 3 digit HTTP status code.
<RESPONSE HEADER> contains the metadata and settings about the response message.
<RESPONSE BODY> contains the representation of the request was successful. Most common formats are JSON, XML or TEXT.
Cisco provides a wealth of free resources that will allow you to experiment with the REST interfaces provided on a range of Cisco Platforms. Head over to DevNet or the DevNet learning labs to follow through scripted examples of REST calls to Spark, APIC-EM and IOS devices.
If you wish to explore further how Cisco can help with leveraging programmatic interfaces on our platforms and services please contact your Account Team.
In next month's Automation and Network Programmability Series we shall take a high level view of Netconf/YANG.
Follow us on twitter:
@ciscodevnet and @netopdevguy