Data Format

  • Data formats are simply a way to store and exchange data in a structured format. One such format is called Hypertext Markup Language (HTML). HTML is a standard markup language for describing the structure of web pages.
  • These are some common data formats that are used in many applications including network automation and programmability:
  • JavaScript Object Notation (JSON)
  • eXtensible Markup Language (XML)
  • YAML Ain’t Markup Language (YAML)
  • The data format that is selected will depend on the format that is used by the application, tool, or script that you are using. Many systems will be able to support more than one data format, which allows the user to choose their preferred one.

Data Format Rules

Data formats have rules and structure similar to what we have with programming and written languages. Each data format will have specific characteristics:

  • Syntax, which includes the types of brackets used, such as [ ], ( ), { }, the use of white space, or indentation, quotes, commas, and more.
  • How objects are represented, such as characters, strings, lists, and arrays.
  • How key/value pairs are represented. The key is usually on the left side and it identifies or describes the data. The value on the right is the data itself and can be a character, string, number, list or another type of data
XML Format
JSON Format
YAML Format

REST and RESTful API

  • Web browsers use HTTP or HTTPS to request (GET) a web page. If successfully requested (HTTP status code 200), web servers respond to GET requests with an HTML coded web page.
  • Simply stated, a REST API is an API that works on top of the HTTP protocol. It defines a set of functions developers can use to perform requests and receive responses via HTTP protocol such as GET and POST.
  • Conforming to the constraints of the REST architecture is generally referred to as being “RESTful”. An API can be considered “RESTful” if it has the following features:
  • Client-Server– The client handles the front end and the server handles the back end. Either can be replaced independently of the other.
  • Stateless– No client data is stored on the server between requests. The session state is stored on the client.
  • Cacheable– Clients can cache responses to improve performance.

RESTful Implementation

A RESTful web service is implemented using HTTP. It is a collection of resources with four defined aspects:

  • The base Uniform Resource Identifier (URI) for the web service, such as http://example.com/resources.
  • The data format supported by the web service. This is often JSON, YAML, or XML but could be any other data format that is a valid hypertext standard.
  • The set of operations supported by the web service using HTTP methods.
  • The API must be hypertext driven.

RESTful APIs use common HTTP methods including POST, GET, PUT, PATCH and DELETE. As shown in the following table, these correspond to RESTful operations: Create, Read, Update, and Delete (or CRUD).

URI

These are the parts of the URI https://www.example.com/author/book.html#page155 :

  • Protocol/scheme– HTTPS or other protocols such as FTP, SFTP, mailto, and NNTP
  • Hostname– www.example.com
  • Path and file name– /author/book.html
  • Fragment– #page155

RESTful Request

These are the different parts of the API request:

  • API Server– This is the URL for the server that answers REST requests. In this example it is the MapQuest API server.
  • Resources– Specifies the API that is being requested. In this example it is the MapQuest directions API.
  • Query– Specifies the data format and information the client is requesting from the API service. Queries can include:
  • Format– This is usually JSON but can be YAML or XML. In this example JSON is requested.
  • Key– The key is for authorization, if required. MapQuest requires a key for their directions API. In the above URI, you would need to replace “KEY” with a valid key to submit a valid request.
  • Parameters– Parameters are used to send information pertaining to the request. In this example, the query parameters include information about the directions that the API needs so it knows what directions to return: “from=San+Jose,Ca” and “to=Monterey,Ca”.

RESTful API Applications

  • Postman: Postman is an application for testing and using REST APIs. It contains everything required for constructing and sending REST API requests, including entering query parameters and keys. 
  • Python: APIs can also be called from within a Python program. This allows for possible automation, customization, and App integration of the API. 
  • Network Operating Systems: Using protocols such as NETCONF (NET CONFiguration) and RESTCONF, network operating systems are beginning to provide an alternative method for configuration, monitoring, and management. 

Configuration Management Tools

  • The goal of all of these tools is to reduce the complexity and time involved in configuring and maintaining a large-scale network infrastructure with hundreds, even thousands of devices. These same tools can benefit smaller networks as well.

REST API Lab

CURL or even better Postman.

Router config:
conf t
username admin priv 15 secret Cisco!23
ip http secure-server
ip http authentication local
restconf
int gig 1
ip add 192.168.1.56 255.255.255.0
no shut
router ospf 1
network 0.0.0.0 255.255.255.255 area 0
ip route 0.0.0.0 0.0.0.0 192.168.1.1
router eigrp 1
net 0.0.0.0
end
debug ip http ssl error

remember authentication/authorization
-user “admin:Cisco!23”
remember header:

Content-Type:application/yang-data+json

GET:
https://sandbox-iosxe-recomm-1.cisco.com/restconf/data/ietf-interfaces:interfaces
https://192.168.10.117/restconf/data/Cisco-IOS-XE-native:native/
https://192.168.10.117/restconf/data/Cisco-IOS-XE-native:native/router/
https://192.168.10.117/restconf/data/Cisco-IOS-XE-native:native/router/router-ospf
https://192.168.10.117/restconf/data/Cisco-IOS-XE-native:native/interface/
https://192.168.10.117/restconf/data/Cisco-IOS-XE-native:native/interface/
https://192.168.10.117/restconf/data/ietf-interfaces:interfaces
https://192.168.10.117/restconf/data/Cisco-IOS-XE-interfaces-oper:interfaces
https://192.168.10.117/restconf/data/Cisco-IOS-XE-interfaces-oper:interfaces/interface=GigabitEthernet1
https://192.168.10.117/restconf/data/Cisco-IOS-XE-interfaces-oper:interfaces/interface=Loopback0

POST:
https://192.168.10.117/restconf/data/ietf-interfaces:interfaces

Body:

Ansible Server

yum update -y
yum install epel-release -y
yum install ansible -y
cd /etc/ansible
ls
nano  ansible.cfg
#host_key_checking=false
remove hashtag after clicking i and then esc :wq
nano hosts
[routers]
192.168.10.117

[routers:vars]
ansible_user=admin
ansible_password=Cisco123
ansible_connection=network_cli
ansible_network_os=ios
ansible_port=22

On the network Device you need to enable SSH
hostname R1
username admin priv 15 pass cisco
ip domain name cisco.com
line vty 0 4
transport input ssh
login local
enable pass cisco
crypto key gen rsa
1024

[routers]
sandbox-iosxe-latest-1.cisco.com

[routers:vars]
ansible_user=developer
ansible_password=C1sco12345
ansible_connection=network_cli
ansible_network_os=ios
ansible_port=22

37
Created on

Automation Quiz

Test Your Understanding

1 / 7

Which character is used to separate JSON key/value pairs?

2 / 7

What is an architectural constraint to which a true RESTful API web service must adhere?

3 / 7

What is JSON?

4 / 7

Which two configuration management tools are developed using Python? (Choose two.)

5 / 7

In the RESTful API request example, ht​tp://ww​w.mapquestapi.com/directions/v2/route?outFormat=json&key=KEY&from=San+Jose,Ca&to=Monterey,Ca, which term describes the component directions/v2/route?

6 / 7

Which web service API can use multiple data formats including JSON, XML, and YAML?

7 / 7

A programmer is using Ansible as the configuration management tool. Which term is used to describe a set of instructions for execution?

Your score is

The average score is 67%

0%