In this example, i'm running an ubuntu 18 zero for three virtual machine in VMware Fusion on my mac.
Now you could do it directly on a mac, but I'm going to do it in a boon punto so that if you're using
a Windows machine, I would suggest you run an open door shell or run an ubuntu VM or something.
Seriously, linux is the way to go, so just learn Linux.
So I'm going to do this by creating a file called XY py.
In a previous video I showed you how to install Python on ubuntu, so I'm assuming that's already done.
What I've done here is created a script that imports requests.
Requests is a great way to interact with a web interface such as a rest API.
So again, rather than reinventing the wheel, I'm just going to import that library.
And then you'll see that my code is very simple.
I'm going to allow self signed certificates.
So if you don't do this, it'll fail once again, just like it would in Postman.
So I'm going to add this so that it ignores self signed certificates, basically accepts them.
Here are our credentials.
So I'll copy that to my Ubuntu computer paste that in.
That's the first part of the code.
Second part of the code is notice the URL.
This is exactly the same URL that we used in Postman.
It's this URL.
It's exactly this URL.
But I've got that in a Python script.
Now notice the headers here.
We've got content type application accept application yangu data JSON.
That is the same as here.
Now, as I said, you can get away just using except but for a post I had to use accept and content
type.
So here I've just got both in the script and what we're going to do is run a get this is a variable
that stores that information.
So we're doing requests don't get this is a method of requests.
We are going to use this URL, specify our username and password which was specified over here.
Headers that we're using are these headers and we are not going to verify our certificates.
So I'll copy that and paste that in to the Ubuntu server.
So here is our entire script.
Very simple.
Only a few lines and then I'll save that script and I'm going to run Python 3xpy and hopefully we'll
see the interfaces on the router and there you go, all the interfaces on the router.
There's Harvey once again.
Who configured gigabit two on the router.
Okay.
But just to prove the point, let's go to Postman and let's create interface loopback.
One, two, three, four and click send and go back to the Python script and run it again.
Notice we've created loopback.
One, two, three, four.
Let's create loopback.
One, two, three, five.
That tells me it's created.
Run my script again.
There it is.
And just for fun, let's duplicate this.
And what we'll do is in the body say, let's create a loopback of 2000 and let's say I can see this
using Python.
And let's make this.
2.2.2.2.
Click Send.
It's now been created back in a ubuntu python 3xpy.
There you go.
Okay.
So I've shown you how to get a list of interfaces using a rest API and postman.
Then I showed you how to do that using a python script.
I showed you how to create interfaces using Postman.
I showed you how to delete interfaces using Postman.
Postman is a great way to get started.
If you're not sure about the coding, then use the graphical user interface to get started.
I've once again given you all the steps in this PowerPoint presentation, so download the PowerPoint
presentation and just follow the steps and you should be able to do this yourself.
Okay.
Hopefully you've learned something.
Hopefully you're now more comfortable using a rest API.