Free CCNP 350-401 ENCOR Complete Course: 6.4: REST APIs Part 3

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
- In this video, we're going to continue our discussions of the REST API. In the previous video which I've linked here and below, I showed you how to interact with a Cisco DNA center servers REST API. In this video we're going to connect to a Cisco IOS XE device. So rather than connecting to a controller, we're connecting directly to a networking device. For the CCNP exam, you need to know REST APIs. You need to know for instance the status codes that you get back. So do you know what a 404 error code is? That's quite a well known error code or status code. So 404, you need to know what that is. You need to know for instance what 200 is. You need to know some of the other status codes for the CCNP exam. Once again, you could interact with a network device using the CLI. But in this video we're going to interact with a network device using the REST API. For a lot of people, this doesn't necessarily make a lot of sense when they've only got one device. But remember we are looking at scaling. So if you've got 100, or 200, or 1000 devices, it makes a lot more sense to programmatically change the configurations of network devices using a well known exposed API. So once again, in this video, I'm gonna show you how to interact with the REST API of a Cisco IOS XE device using Postman. Enough said, let's get started. (upbeat music) Now rather than interacting with DNA center, let's just talk directly to a router. The advantage of using DNA center, is you can talk to a controller that's then managing many, many devices. But you can also talk directly to a device, if it supports a REST API. So in this example, we're gonna use the Cisco DevNet IOS XE always on sandbox. This is its DNS name. This is the protocol that we're gonna use. Port number, username, password. And we're gonna use Postman once again. Now very important. Before you do anything else. And I wanna show you this in both Windows and on a Mac. In Postman, go to file, on your Windows installation settings, and make sure that you turn off SSL certificate verification. The router in this example is using a self-signed certificate. If you don't turn this off, it's not gonna work. You're gonna drive yourself crazy. You have to override self-signed certificates to make this work. On a Mac, you need to go to Postman preferences, and disable SSL certificate verification. Before you do anything else, make sure you've done that. Otherwise you're gonna drive yourself crazy. So, I've got some pre-built stuff here. But again, let's not use that. Let's do stuff manually, so that you can see how it works. I'll close all these tabs. New tab, untitled request. First thing I wanna do is get a list of interfaces on the router. This is the URL that I'm gonna use. So I'm simply going to paste that in here. It's a GET statement. We're using GET. URL is that. But we need to put our Authorization information in. It's basic authentication. You can see that here in the PowerPoint slide, username is developer, password of Cisco12345, with a second character being a one. So we're gonna use developer as our username, password is that. This should connect to that router and give us a list of interfaces on the router. Notice it's returned the information, in this example, in XML format. So I can see gigabit one. This is the management interface. Don't touch it. IP address is this. Netmask is this, or subnet mask is that. Here's another interface that was configured by REST. Someone else is configuring this. So this is an always on sandbox. So anyone can connect to this. So you'll see other people creating stuff on the router. Now, XML like this isn't that easy for us as a human to read. You can see someone has added Loopback 100 here using RESTCONF. Someone has added in this example Loopback 103, using the CLI and netmiko. Someone has also added a Loopback of 200 using Python. XML isn't the easiest to read. Let's rather change this to JSON formatting. So to do that, I'm gonna go to headers, and what we're going to do, is create a key called Accept. And the value of that key, is gonna be application, yang hyphen data plus JSON. So that. And then I'm gonna click Send. And notice we've got JSON formatting now, rather than XML formatting. That's probably a lot easier to read for us as humans. So we can see, ietf interfaces. Notice this is an array. Square brackets there. Gigabit interface is this. We're told not to touch it. But there's the IP address. Here's interface gigabit two configured by Harvey, with his information. Here's gigabit two 100. And other interfaces that have been added. You can see suddenly we've got Loopback 88 here. So there are other people once again working on this. Here's Loopback 99. Loopback 100. So once again, other people are configuring this device. But there you go. That is an example of using REST to connect to a router, and retrieve information back. Notice we're using HTTPS. We are not using Net Config, we're not using SSH. We're using HTTPS. REST API call. Now, one thing I'll say is if you have problems, then add this second key. So if you have problems, where it doesn't send back the information, then add this second key, but in my test, it's not required. But it will be required when you wanna add an interface. So in the PowerPoint slide, once again, I've given you all that information. But now let's use a POST. And let's add an interface. So POST will allow us to add something. So I'm gonna click on this tab, put the URL in. It's a POST. We need to use the same username and password. So not a GET, but POST. Go to Authorization. In this example, we're using basic authentication. On DNA center, we were using tokens. So X-Auth-Token for authorization. Here we're using, basic authentication. So, username is developer, password is Cisco12345. That's correct. We need to go to headers. And we need to add two headers here. Key one is Accept. Once again, we wanna use JSON. And we're gonna do the same thing again for key two. But key two is gonna be Content-Type. This kind of stuff is determined by the developer. In other words by the API. If you wanna interact with an API, you need to send the information as required by that API. And the developers of that API will decide what that API requires. So don't worry too much about what the values are. This is the API developed by, the Cisco IOS XE people. And we're interacting with that API now. Now step three is we need to add this to the Body. Because we wanna create a specific interface, we need to tell the router what interface we wanna create. So to do that, we're gonna use this text in the Body of our API call. So go to Body, go to raw and paste this in. Now because other people just go back to GET, are creating interfaces on this router, I've specifically used a high-end Loopback number. So that I'm not interfering with what they're doing and they're not interfering with what I'm doing. So I'm gonna create a Loopback of a 1234 and say that this was added using RESTCONF. IP address is gonna be 1234, subnet mask is gonna be slash 32. So if I go back to the GET statement and click Send, notice that Loopback doesn't exist on the router. We've got some physical interfaces, we've got some Loopbacks, but we don't have Loopback 1234. So back to our POST. I've put the URL in. Authorization is basic authorization using developer, password of Cisco. Headers. I've specified Accept and Content-Type. Body, I've put this information in. Click Send. We have got 201. Request has been fulfilled, and resulted in a new resource being created. That's good. So let's confirm the results. So go back to GET, click Send, scroll down, and notice, here's our Loopback interface. Now if I try to create that again, I'm getting an error, 401 Conflict. Object already exists. So, I've already got that interface. So I can't create it. But if I created another one. Let's create a Loopback 1235, and click Send. We've got 201 created. Go back to GET, click Send. Notice 1235 exists, and so does 1234. So there's an example of creating a Loopback interface, on a router, using a REST API. Direct connection to the REST API of the router. Okay, so I've once again put that in the PowerPoint presentation for you. Let's delete that Loopback. So I'm gonna create a new tab here, but this is a delete. URL is that. Notice at the end here, I've specified the interface that I want to delete. Authorization is gonna be Basic Authorization, using our credentials. We have to have a key of Accept. So go to headers. Key of accept here. Application is yang data plus JSON. Click Send. We're told that there's no content. Let's do a Send again here. Notice the interface has been deleted. Let's change that to interface 1345. I should have checked that first. I'll do it again in a moment. But notice here's 1235. So that exists. 1234 is deleted. But let's delete 1235. No content has been returned. That's correct. So back on our GET, click Send. Notice 1235 is gone. Let's create 1234 once again. If you want to you can duplicate this tab. So now I've got two POSTs. And what I could do is do a POST for 1234 and 1235. So let's create. So it's a post. Let's create a Loopback 1234. It's created now. So back on our GET statement, click Send. Notice 1234 has been created. Let's create 1235, click Send. It says created. That's good. Do GET again. It's created. But if I delete, in this case 1234, click Send. No content returned. Previously, that Loopback was created. But now it's gone. We've got Loopback 200, and then Loopback 1235. 1234 has gone. Let's delete 1235, click Send. Do GET once again. Notice that Loopback has gone. So I've shown you now, how to use Postman, to interact directly with a router, and find out the interfaces on the router, create a new interface, as well as delete an interface. Rest APIs. That is an example of using rest APIs on an individual device. But I've also shown you previously how to do that with DNA center. So DNA center once again. REST API allows me to interact with a whole bunch of devices. Here, I'm interacting with one device. Now the comment I always get is, "David I could just use the CLI, might be quicker". But don't forget that with programming, you can scale. So I'm gonna show you now, how to get to the interfaces of one router. But if I had 200 routers, I could write a Python script with a loop. No human would be able to compete with a Python script written properly. Or an Ansible script written properly, where it's connecting to many devices and doing things on many devices. You may be quick on one device. But if I write my script right, there's no way a human can compete. If I've got 100 or 200 devices or 1000 devices. (upbeat music)
Info
Channel: David Bombal
Views: 19,394
Rating: undefined out of 5
Keywords: ccnp, encor, dna center, cisco dna, cisco sdn, cisco dna center, rest, rest api, restful api, 350-401, python, json, ccna, ccnp encor, ccnp enterprise, ccnp training, new ccnp, ccnp study, cisco certifications, cisco training, cisco, ccnp certification, encor 350-401, ccnp automation, ccie encor, cisco ccnp exam, ccie enterprise, cisco certification 2020, cisco ccnp, cisco encor training, cisco encor exam, ccnp review, cisco ccna, ccna study, ccna training, cisco encor test
Id: Bqd901dKIB4
Channel Id: undefined
Length: 14min 21sec (861 seconds)
Published: Sun May 10 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.