There are a lot of talk about APIs right now. Every vendor has an API, but not all are created equal. What does an API even mean? I’m not going to get too wrapped around definitions. But I’ll provide you a link
A more formal definiition of REST may be found here. For my purposes, I propose the following:
Something that I can work with using the HTTP protocol and probably returns data in XML or JSON.
I’m working with HP’s Intelligent Management Center and it’s eAPI, which offers a RESTful interface to the network management system which will return both XML and JSON.
Here’s an example of a call using XML
Update: For those who noticed – The URL for both are the same. But the content of the HTTP request actually shows a slightly different story
Here’s the Wireshark of the XML request. If you look at the trace below, you can see the Accept: application /xml\r\n which shows that the request is asking for XML.
Here’s an example of a call using JSON.
Here’s the JSON request which is essentially the same except the accept: portion in this shows application as JSON.
As you can see they carry the exact same data, but the way the data is structured is slightly different. From what I can tell, programatically speaking, there’s no difference in that you can definitely work with either one easily.
For right now, I’ve chosen to focus on the just XML under the theory that if I focus on figuring out how to work with just XML for now, I can go back and learn how to work with JSON later after my overall skills as a programer have increased.
It’s a theory.
Note: For those of you who haven’t seen this interface, it’s a standard ( at least for HP ) RS-Docs interface which provides the documentation for the RESTful interface directly on the machine and allows you to test it. This is also available for the HP SDN controller.
For IMC. it can be accessed at http://localhost:8080/imcrs and will require you to authenticate. BTW the port numbers may also change if you installed in something other than the default state.
RealTimeLocation API – Breaking it Down.
For those of you with keen eyes. You can probably guess that this particular API is used to locate a host on the network. Let’s break it down a little so that we can see what the the return is actually telling us here.
So a couple of quick notes about this list.
- Device ID is an internal numbering scheme that HP IMC uses to keep track of the devices. This has no practical relation to anything outside the IMC system.
- ifDesc is the SNMP ifDesc. You may be tempted to look at this and think “ That must be the description on the interface!!!” You would be wrong. The description you configure on the interface when you type in the command “description This_Is_My_Interface” is actually held in the ifAlias ( 188.8.131.52.184.108.40.206.1.1.18 ) . Blame SNMP for this one.
- ifIndex is the SNMP ifIndex value. This is, again, an easy way for computers to keep track of the number of the port. Also, important to know that on some vendors devices, these values can change with a reboot. Cisco used to have this issue, but they do allow you to make them persist across reboot
So this is a brief introduction into XML and an example of a RESTful API. As you can see, it’s not that intimidating. It’s actually almost readable by a human being.
In the next post. I’m going to look at building some basic python code to use this API directly.
Questions or Comments? Please post below and I”ll be happy to do my best. Again, I’m student in progress here, so please take any answers I give with a grain of salt. If you’re further along on this journey that I am. Please feel free to suggest improvements in the comments as well. I wouldn’t say I’ve got no ego, but I”ll check it at that door if it helps me improve.