Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
181 views
Rest Api
Uploaded by
Abhishek garg
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save REST API For Later
Download
Save
Save REST API For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
181 views
Rest Api
Uploaded by
Abhishek garg
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save REST API For Later
Carousel Previous
Carousel Next
Save
Save REST API For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 13
Search
Fullscreen
2010512028, 12:03 Introduction to REST API Search Q © Introduction to REST API Lesson Contents 1. Configuration 1.1. Router 1.2. Python 1.2.1. GET interface 1.2.2, PUT interface 2. Conclusion In this lesson, welll take a look at what a REST API is. First of all, what is an API? 10351 hitpssnetworklessons.comiscofcenp-encor-360-40 Vintreduction o-rest-ap wn2010512028, 12:03 Introduction to REST API 4 We, as network engineers usually use the command-line interface (CL!) or a GUI to configure or monitor our network devices. Parsing show and debug commands with scripts is difficult because these commands are for humans. To interact with applications or network devices, we can use an Application Programming Interface (API). ‘An API is a software interface which allows other applications to communicate with our application Roy T. Fielding describes REST in his dissertation (chapter 5). t's an acronym for REpresentational State Transfer: * Representational means we transfer the representation of a resource between a server and a client, We use a data format for this representation, typically JSON or XML. * State Transfer means that each operation with a REST API is self-contained. Each request carries (transfers) all information (state) to complete the operation. REST APIs typically use HTTP methods to retrieve or send information between applications. We use the same HTTP methods when we use a web browser to visit a website, but now we use them to interact with an application. HTTP has multiple rnethods, but these four are the most common ones: © * GET: A read-only method to retrieve a specified resource. * POST: Submits data to the specified resource to process. The POST method can also create new resources. * PUT: Updates the specified resource by replacing the existing data, * DELETE: Deletes the specified resource. HTTP is popular so you can use REST APIs in almost any programming language. I mentioned resource several times but didn’t explain exactly what a resource is. A resource is a “thing” you can access and receive or change its representation. On the web, this could be a document or image. With a REST API, it could be a row in a database. We access a resource with a Uniform Resource Locator (URL). That's right, the URLs we also use for websites. A quick example is the following URL: https: //192.168.1.1:55443/api/v1/interfaces/loopback@ We can use this URL to access the Loopback 0 resource on a router. Ill show you in a minute what that looks like in action, hitpssnetworklessons.comiscofcenp-encor-360-40 Vintreduction o-rest-ap 2132008/2023, 12:08 Introduction to REST API | want to visit that website! rG I want to —— retrieve the SS R1's interface a -———— JSON status! © An API must meet 6 guiding constraints if we want to call ita REST API. Another name for an API that meets all constraints is a RESTful service. Understanding these constraints in detail is essential for API developers. The 6 constraints are: * Client-server: The client and server are independent. They interact with each other through requests. that the client initiates. The server listens for requests and answers them. * Stateless: The server doesn't store any state about previous requests. For example, it doesn’t track if a client already requested a resource before. It also doesn't track which resources were requested by actient. * Cacheable: The server includes a version number in its messages. The client can use this to decide whether it should request a resource again or use the cached data. * Uniform interface: The interface is decoupled from the implementation. There are four sub- constraints: © Identification of resources: Each resource must be uniquely identifiable via a URI (Uniform Resource Identifier). hnps:networklessons.comiciscalecnp-encor-350-40 introduction o-est-api ana2008/2023, 12:08 Introduction to REST API 4 server's database, We have to use a representation and neutral data format. When a client wants to update a resource, it has to take the following steps: = Request a representation of the resource. * Update the representation with new data. = Send the representation of the resource to the server. Self-descriptive messages: Each message (request or response) must include enough information so the receiver can understand it. A message requires a media type (for example “application/json’) that tells the receiver how to parse the message. Hypermedia as the engine of application state (HATEOAS): You should be able to discover other areas of the API similar to how a user browses a website. A response from the API should include links to other parts of the API. This way, you can figure out how the API works without referring to external documentation. * Layered system: REST allows a layered system. You could deploy the API on one server and the data ‘on another server. You could add additional layers like a load-balancer in between the client and server. The client can't tell whether it's communicating with an intermediate or end server. Extra layers should not affect communications between the client and the server. * Code on demand (optional): This is an optional constraint. The server usually sends a static representation in SON or XML. The server can optionally include executable code to.a cient. An example is a Java applet or JavaScript. REST has no built-in security features, but if needed we can add these, For example, we can use HTTPS for encryption and usernames or tokens for authentication. 1. Configuration Enough theoretical talk for now. Let's see how we can use a REST API to monitor and configure a Cisco CSR1000v router. Here's the topology welll use: Gi0/2: Li 172.16.1.100 Ze/ TET hnps:networklessons.comiciscalecnp-encor-350-40 introduction o-est-api ana2010512028, 12:03 Introduction to REST API 1.1. Router Let's start with the router. This is a CSR1000v router running !OS XE 16.6.1: Ritshow version | include Version Cisco 10S XE Software, Version 16.06.01 Cisco 10S Software [Everest], Virtual XE Software (x86_64_LINUX_IOSD-UNIVERSALK9-M), Version 16.6.1, RELEASE SOFTWARE (#c2) Want to take a look for yourself? Here you'll find the startup configuration of each device. R1 ~ hitpssnetworklessons.comiscofcenp-encor-360-40 Vintreduction o-rest-ap 5132010512028, 12:03 Introduction to REST API 4 interface Loopback® ip address 1.1.1.1 255.255.255.255 interface Gigabitethernet2 ip address 172.16.1.10@ 255.255.255.0 negotiation auto no mop enabled nto mop sysid ip route 0.0.0.0 0.0.0.0 172.16.1.254 end First, we create a user that has full access to the router: Ri(config)#username admin privilege 15 password admin Also, we activate the shared management interface: R1(config)#virtual-service csr_mgnt Ri(config-virt-serv)#ip shared host-interface Gigabitethernet 2 R1(config-virt-serv)tactivate % Activating virtual-service ‘csr_mgmt', this might take a few minutes. Use ‘show virtual-service list’ for progress. This configuration is all we have to do to enable the REST API. There are some show commands we can use to verify if the REST API is up. The first two commands are to check the status of the virtual service: Riftshow virtual-service list Virtual Service List: Name Status Package Name hitpsnetworklessons.comiscofcenp-encor-360-40 Vinreductiono-rest-ap ana2010512028, 12:03 Introduction to REST API 4 Ifyou want more details, try this: Rifshow virtual-service detail name csr_mgmt Virtual service csr_mgnt detail state Activated Owner rosd Package information Name : dosxe-remote-ngmt.16.06.01.0va Path 1 bootflash:/
[email protected]
Application Name 2 ¢sr_mgmt Installed version : 2017.6 Description CSR-MGHT Signing key type Cisco release key Method SHA-1 Licensing © Name : Not Available Version : Not Available Detailed guest status Process Status Uptime # of restarts nginx up e@Y OW aD @: 4:36 e climgr up ey OW eD O: 4:36 1 restful_api up eY eW @D a: 4:36 e fegicpa Down pnscag Down pnscdme Down Feature status Configuration Restful API Disabled, UP pNsc Disabled, Down hitpsnetworklessons.comiscofcenp-encor-360-40 Vinreductiono-rest-ap m32010512028, 12:03 Introduction to REST API 4 ethd: RX packets:8@7, TX packets:795 eth1: RX packets:29, TX packets:28 Coredump file(s):
[email protected]
, lost+found Activated profile name: None Resource reservation Disk : 756 MB Memory : 512 MB cpu 5% system CPU Attached devices Type Name Alias Nic ieobc_1 —_ieobe NIC dp_133net2 Disk _rootfs Disk Jopt/var © Disk Jopt/var/c Serial/shell serialo Serial/aux serial1 Serial/Syslog serial2 Serial/Trace serial3 Watchdog, watchdog-2 Network interfaces MAC address Attached to interface 54: 0E :00:0B:0C:02 ieobe_1 FA:16:3E:DA:62:4F VirtualPortGroup33 Guest interface Interface: eth1 ip address: 172.16.1.100/24 hitpsnetworklessons.comiscofcenp-encor-360-40 Vinreductiono-rest-ap ana2010512028, 12:03 Introduction to REST API Address/Mask Next Hop Int. Resource admission (without profile) : passed Disk space: 756HB Memory 2 512MB cpu 1 5% system CPU vcpus : Not specified ‘Another command is show renote-nanagement which gives a quick overview: Rifshow renote-management status Remote managenent release version: 2017.6 Process status Uptime # of restarts e nginx up ey OW @D O: 3: 3 e climgr up ey ew aD @: 3: 3 1 restful_api up ey ew eD @: 3:3 e fegicpa Down pnscag Down pnscdme Down Feature Status Configuration Restful API Disabled, UP pNsc Disabled, Down Network stats: etho: RX packets:554, TX packets:548 ethl: RX packets:29, TX packets:28 That's all we have to configure on our router. hitpssnetworklessons.comiscofcenp-encor-360-40 Vintreduction o-rest-ap ona2010512028, 12:03 Introduction to REST API 4 repository. 1.2.1. GET interface Let’s start with a simple example. The script has two functions: © get token © get interface First, we authenticate with the router using a username and password, When successful, we receive a token, We then use an HTTP GET method to retrieve information about the loopback 0 interface. Let's run the script: python get-interface.py We received token: VqtxSiHJpuRytNQYoTF2S1zFd]IRgmAPFBZM4v9h+gE= Here is the interface information: @ "kind": “object#interface", “description”: "", if-name": “Loopbacke", “proxy-arp": true, “subnet-masi "255.255.255.255", .cmp-unreachable” true, “ipvé-enable": false, "nat-direction": "", ‘cmp-redirects": true, p-address": "1.1.2.1", "verify-unicast-source": false, “type”: “Loopback” ‘The output above is looking good. The router reports the configuration of the loopback 0 interface. 4.2.2, PUT interface hitpssnetworklessons.comiscofcenp-encor-360-40 Vintreduction o-rest-ap ron2010512028, 12:03 Introduction to REST API * get_token * put interface The get_token function is the same as in our previous script. The put_interface function adds a header that, specifies that the payload is in JSON format. We then send the payload with our updated configuration to the router. python put-interface.py We received token: VatXSiHJpURytNQVoTF2S1zFdJIRgMAPFEZM4VSh+ge= The router responds with status code: 204 The router responds with a 204 status code. This status code means that the server successfully fulfilled the request and that there is no additional content to send. 2. Conclusion You have now learned what a REST API is and how to use it on the Cisco CSR1000v router. * ANAPIis a software interface so that applications can interact with our application. * REST is an architecture style, described in a dissertation by Roy T. Fielding, * AREST API is an API that meets 6 constraints. * Most REST APIs use HTTP methods and JSON or XML as the data format. * We used the HTTP GET method to retrieve interface information and the HTTP PUT method to update its configuration, hope you enjoyed this lesson. Feel free to leave a comment if you have any questions. Previous Lesson Next Lesson Introduction to Python Network Automation and) Orchestration ® Tags: API, SDN Forum Replies hitpssnetworklessons.comiscofcenp-encor-360-40 Vintreduction o-rest-ap 32010512028, 12:03 Introduction to REST API 4 |.am new to Python and starting my first lab. In my virtual lab | have 3 CSR1000v connected to Ubuntu device with Python 3 installed on it and they can talk to each others. | have no problems with the router config but when it gets to the script | have no idea where and how to write the script and how to push it to the router. Can you clarify the Python part please? Thank you Hany GQ werraes Hello Hany In order to get a good grasp of Python it would be a good idea to find an online tutorial there are literally hundreds ‘out there) that can get you started scripting. A suggestion would be to go to https://www.learnpython.org/ which is a start from scratch introduction that can give you the basics you need for scripting. But you can do your awn search and find the course that will be best for you. ‘Once complete, if you have specific questions about how to apply it to networking and your virtual lab, well be able to @ more specifically help you out. | hope this has been helpfull Laz Ey eros HiRene, iim getting the output below, when trying to activate esr_mgmt, “*May 6 19:20:30,764: %&VMAN-3-VIRT_INST_INTERFACE: Fo: van: Virtual Service[csr_mgrnt]: Network interfaces::The number of network interfaces required do not match the number configured::Number defined: 1, number configured: (0 *May 6 19:20:31,746: #VIRT_SERVICE-S-ACTIVATION. STATE: Failed to activate virtual service csr_mgmt ‘And I don't see the “ip shared host.interface” command available: hepsilfedn- forum networklessons.com/uploads/default/original/2X/3/34d2e0132026dd24542e4c767619b708ec98eFfc-png hitpssnetworklessons.comiscofcenp-encor-360-40 Vintreduction o-rest-ap rane2008/2023, 12:08 Introduction to REST API Thanks eepises Hetowws ‘Thats interesting... could be that the syntax is different for a particular feature depending on the 1OS being used. In the lesson, Rene is using a CSR1000v router running IOS XE 15.6.1, What device are you using? Laz Gi ribeirouls Hi tim running the version below on EVE-NG. | thinkit was the only image that was available for free on Cisco's website Routertsh ver Cisco 10S XE Software, Version 03.17.02 - Standard Support Release Cisco 10S Software, CSR1OOOV Sofware (486,64 LINUX IOSD-UNIVERSALKS-M), Version 15.41)82, RELEASE SOFTWARE 3) (fea) Thanks, Le $2 18 more replies! Ask a question or join the discussion by visiting our Community Forum Disclaimer Privacy Policy Support About © 2013 - 2023 NetworkLessons.com 52189 hnps:networklessons.comiciscalecnp-encor-350-40 introduction o-est-api ran
You might also like
REST API Presentation
PDF
No ratings yet
REST API Presentation
35 pages
Describe Characteristics of REST
PDF
No ratings yet
Describe Characteristics of REST
12 pages
Python and REST APIs - Interacting With Web Services - Real Python
PDF
100% (1)
Python and REST APIs - Interacting With Web Services - Real Python
35 pages
Rest Api
PDF
No ratings yet
Rest Api
10 pages
04 Building RESTful Services
PDF
No ratings yet
04 Building RESTful Services
78 pages
Workshop 7
PDF
No ratings yet
Workshop 7
26 pages
Rest Youtube 5
PDF
No ratings yet
Rest Youtube 5
39 pages
Rest Youtube 4
PDF
No ratings yet
Rest Youtube 4
34 pages
135.1 REST API security
PDF
No ratings yet
135.1 REST API security
4 pages
Rest 101
PDF
No ratings yet
Rest 101
35 pages
Module 5.1 Intro To The Cloud
PDF
No ratings yet
Module 5.1 Intro To The Cloud
16 pages
Ecs781p 5 Rest API
PDF
No ratings yet
Ecs781p 5 Rest API
40 pages
Rest API
PDF
No ratings yet
Rest API
3 pages
RESTful API Design Principles
PDF
No ratings yet
RESTful API Design Principles
3 pages
Tutorial: Building A Restful Api With Flask: What Is An Api?
PDF
No ratings yet
Tutorial: Building A Restful Api With Flask: What Is An Api?
9 pages
What Is REST - REST API Tutorial
PDF
No ratings yet
What Is REST - REST API Tutorial
22 pages
REST Basics
PDF
No ratings yet
REST Basics
18 pages
Cloud computing Unit-2.
PDF
No ratings yet
Cloud computing Unit-2.
58 pages
Unit 4
PDF
No ratings yet
Unit 4
19 pages
Group 1 Laboratory#5 NodeMCU IOT - RESTful API Basic and Consuming RESTFUL API
PDF
No ratings yet
Group 1 Laboratory#5 NodeMCU IOT - RESTful API Basic and Consuming RESTFUL API
19 pages
REST API (1)
PDF
No ratings yet
REST API (1)
5 pages
Web Services API
PDF
No ratings yet
Web Services API
24 pages
Rsseco En-Us SG m12 Apisrest
PDF
No ratings yet
Rsseco En-Us SG m12 Apisrest
15 pages
Fsa CS6 Rest
PDF
No ratings yet
Fsa CS6 Rest
24 pages
Edgelink RESTful API Specification_v2.0
PDF
No ratings yet
Edgelink RESTful API Specification_v2.0
99 pages
Rest Api
PDF
No ratings yet
Rest Api
4 pages
Fall 21 Lecture9 APIs
PDF
No ratings yet
Fall 21 Lecture9 APIs
68 pages
Rest Architecture
PDF
No ratings yet
Rest Architecture
18 pages
11.3.1-ReST
PDF
No ratings yet
11.3.1-ReST
13 pages
REST+API+Networking+Concepts+ +Participant+Guide
PDF
No ratings yet
REST+API+Networking+Concepts+ +Participant+Guide
47 pages
Rest With Spring: Description
PDF
No ratings yet
Rest With Spring: Description
5 pages
REST
PDF
No ratings yet
REST
47 pages
Rest 101: The Beginner'S Guide To Using and Testing Restful Apis
PDF
No ratings yet
Rest 101: The Beginner'S Guide To Using and Testing Restful Apis
35 pages
REST Udemy
PDF
No ratings yet
REST Udemy
47 pages
REST Vs GraphQL
PDF
No ratings yet
REST Vs GraphQL
37 pages
REST API
PDF
No ratings yet
REST API
14 pages
Security Is Not.: A REST Web Services Gateway
PDF
No ratings yet
Security Is Not.: A REST Web Services Gateway
7 pages
API's and HTTP With Python
PDF
No ratings yet
API's and HTTP With Python
45 pages
Restful (Web) Applications in Practice: Nupul Kukreja Cs 578 7 November 2012
PDF
No ratings yet
Restful (Web) Applications in Practice: Nupul Kukreja Cs 578 7 November 2012
47 pages
Rest Youtube 2
PDF
No ratings yet
Rest Youtube 2
21 pages
Restful API Design
PDF
No ratings yet
Restful API Design
25 pages
REST API (2)
PDF
No ratings yet
REST API (2)
5 pages
Apis
PDF
No ratings yet
Apis
4 pages
RESTful APIs
PDF
No ratings yet
RESTful APIs
13 pages
Apimicrosft
PDF
No ratings yet
Apimicrosft
172 pages
Restful-Api-Design Documentation: Release 1.0
PDF
No ratings yet
Restful-Api-Design Documentation: Release 1.0
23 pages
IPT201_UNIT2
PDF
No ratings yet
IPT201_UNIT2
47 pages
Restful Cheat Sheet
PDF
100% (1)
Restful Cheat Sheet
8 pages
REST API Interview Questions
PDF
No ratings yet
REST API Interview Questions
7 pages
LectureV Rest WebService
PDF
No ratings yet
LectureV Rest WebService
26 pages
Cisco ASA REST API - Part I - Getting Started - IT Playground Blog
PDF
No ratings yet
Cisco ASA REST API - Part I - Getting Started - IT Playground Blog
3 pages
Week 6
PDF
No ratings yet
Week 6
17 pages
NF Registration
PDF
No ratings yet
NF Registration
18 pages
REST API
PDF
No ratings yet
REST API
5 pages
Dzone Refcard129 Restfularchitectureupdated
PDF
No ratings yet
Dzone Refcard129 Restfularchitectureupdated
7 pages
Rest Api Interview Questions
PDF
No ratings yet
Rest Api Interview Questions
7 pages
COMSCPBTech75941A2rWebrPr - Chapter 5 - REST Architectural Style
PDF
No ratings yet
COMSCPBTech75941A2rWebrPr - Chapter 5 - REST Architectural Style
35 pages
14-Cisco ISE Lab
PDF
No ratings yet
14-Cisco ISE Lab
4 pages
08 Installing+EVE NG
PDF
No ratings yet
08 Installing+EVE NG
10 pages
71-DNS Filter
PDF
No ratings yet
71-DNS Filter
8 pages
68-Web Filter Lab
PDF
No ratings yet
68-Web Filter Lab
12 pages
11-Upload Other Images in EVE
PDF
No ratings yet
11-Upload Other Images in EVE
6 pages
72-Application Control
PDF
No ratings yet
72-Application Control
2 pages
62-Introduction AAA
PDF
No ratings yet
62-Introduction AAA
4 pages
IS-IS Route Leaking
PDF
No ratings yet
IS-IS Route Leaking
20 pages
S6700 Series Switches Hardware Description
PDF
No ratings yet
S6700 Series Switches Hardware Description
579 pages
IS-IS Redistribution
PDF
No ratings yet
IS-IS Redistribution
12 pages
IS-IS Summarization
PDF
No ratings yet
IS-IS Summarization
12 pages
MA5600T (N63E-22) Quick Installation Guide 07
PDF
No ratings yet
MA5600T (N63E-22) Quick Installation Guide 07
31 pages
IS-IS Filtering
PDF
No ratings yet
IS-IS Filtering
12 pages
Lec-11 Multicast PIM Prune Override
PDF
No ratings yet
Lec-11 Multicast PIM Prune Override
16 pages
IS-IS Metric
PDF
No ratings yet
IS-IS Metric
9 pages
Lec-8 Why Do We Need QoS On LAN Switches
PDF
No ratings yet
Lec-8 Why Do We Need QoS On LAN Switches
4 pages
Lec-10 Multicast PIM Assert Explained
PDF
No ratings yet
Lec-10 Multicast PIM Assert Explained
12 pages
IPv6 Redistribution Between RIPNG and OSPFv3
PDF
No ratings yet
IPv6 Redistribution Between RIPNG and OSPFv3
7 pages
SNMPV 2
PDF
No ratings yet
SNMPV 2
4 pages
Lec-12 Multicast PIM Register Message
PDF
No ratings yet
Lec-12 Multicast PIM Register Message
8 pages
Lec-8 Multicast PIM Designated Router
PDF
No ratings yet
Lec-8 Multicast PIM Designated Router
10 pages
SNMP
PDF
No ratings yet
SNMP
12 pages
Cisco NetFlow
PDF
No ratings yet
Cisco NetFlow
10 pages
Lec-6 Multicast RPF (Reverse Path Forwarding)
PDF
No ratings yet
Lec-6 Multicast RPF (Reverse Path Forwarding)
14 pages
IPv6 Solicited Node Multicast Address
PDF
No ratings yet
IPv6 Solicited Node Multicast Address
5 pages
Ipv6 Summarization Example
PDF
No ratings yet
Ipv6 Summarization Example
4 pages
Stateless Autoconfiguration For IPv6
PDF
No ratings yet
Stateless Autoconfiguration For IPv6
5 pages
IPv6 Address Types
PDF
No ratings yet
IPv6 Address Types
6 pages
Shortening of Ipv6
PDF
No ratings yet
Shortening of Ipv6
4 pages
Cisco Press - IS-IS Network Design Solutions
PDF
No ratings yet
Cisco Press - IS-IS Network Design Solutions
352 pages