As per wiki, "An application programming interface (API) is a computing interface which defines interactions between multiple software intermediaries. It defines the kinds of calls or requests that can be made, how to make them, the data formats that should be used, the conventions to follow, etc."
I also like one more definition from Kin Lane API 101 guide, "API allows your product or service to talk to other products or services".
APIs can work with any programming language, with the most popular approach to delivering web APIs being REST, or Representational State Transfer. REST is an API framework built on the top of HTTP protocol.By using REST API, request sent to the server and JSON and XML is received as response.
For network engineers, all need to understand that client(web app) will request the data in some data format from server. Server will send the response in particular data format to application.
Before moving ahead, need to understand the URI syntax as most of API calls will be in the given as per below format
Host:
IP address, Web Address and Port Numbers
Resource:
Location of Interested Data On Server
Parameters:
What need to be fetched
Below are the different type of HTTP requests which can be sent to server:
Function | Purpose | Remarks |
---|
Post | Create Request | Create New Object |
Get | Read Request | Read The Existing Object Or Fetch Existing Resources Details |
Put | Update Request | Update the Existing Resources |
Delete | Delete Request | Delete Existing Resources |
Once request is sent, we have to wait for the response. Response can have below mentioned codes which can be used to understand in case of successful response or unsuccessful response.
Status Code | Purpose |
---|
200 | Create Request |
201 | OK |
400 | Created |
401 | Unauthorised |
403 | Forbidden |
404 | Not Found |
500 | Internal Server Error |
503 | Service Unavailable |
Let's get our hands dirty. I am using CISCO always on apic controller sandbox for simulating restapi along with POSTMAN as restapi client.
Open you postman client add the static info or if you want to use it for multiple requst during that case better you create enviorment varibles. I have already created a variable enviorment and sending the GET request to APIC controller: {{ apic}} = sandboxapicem. Replace apic with sandboxapicem
HTTP GET Request: After autnrication, this request is requesting server to share the list of network devices.
https://{{apic}}.cisco.com/api/v1/network-device
HTTP GET Response: The below response will come in JSON. Removed rest of the part due to brevity.
{
"response": [
{
"location": null,
"type": "Cisco 3500I Unified Access Point",
"serialNumber": "FGL1548S2YF",
"errorCode": "null",
"role": "ACCESS",
"family": "Unified AP",
"macAddress": "68:bc:0c:63:4a:b0",
"softwareVersion": "8.1.14.16",
"lastUpdateTime": 1590153808018,
"locationName": null,
"tagCount": "2",
"hostname": "AP7081.059f.19ca",
"inventoryStatusDetail": "NA",
"upTime": null,
"series": "Cisco 3500I Series Unified Access Points",
"errorDescription": null,
"lastUpdated": "2020-05-22 13:23:28",
"roleSource": "AUTO",
"apManagerInterfaceIp": "10.1.14.2",
"bootDateTime": null,
"collectionStatus": "Managed",
"interfaceCount": null,
"lineCardCount": null,
"lineCardId": null,
"managementIpAddress": "10.1.14.3",
"memorySize": "NA",
"platformId": "AIR-CAP3502I-A-K9",
"reachabilityFailureReason": "NA",
"reachabilityStatus": "Reachable",
"snmpContact": "",
"snmpLocation": "default location",
"tunnelUdpPort": "16666",
"instanceUuid": "cd6d9b24-839b-4d58-adfe-3fdf781e1782",
"id": "cd6d9b24-839b-4d58-adfe-3fdf781e1782"
},
No comments:
Post a Comment