API Basics by Ritul Chaudhary
SDN - Software defined networking uses software to define/modify networks. Before SDN: the data plane and control plane were tied together as one.
What SDN does: on a network device, data enters & leaves through the data plane decisions of what to do with the data are made by the control plane this allows network configuration & decisions to be completed through a remote control plane. to make SDN features on these devices accessible over the network, they are exposed through an API
API: Application Programming Interface REST: REpresentational State Transfer An API enables 2 pieces of software to communicate with each other.
What is REST? REST is an API framework built on HTTP when you combine REST and API, you see a simple service interface that enables applications or people to use HTTP protocol to request objects/information a REST API service sends all requests & responses over TCP/TLS connections using text
A Look under the hood at REST Protocol: http:// or https:// indicates whether the server host is open (http) or secured (https). Domain name: maps.googleapis.com is the domain name of the server or host that is providing the web service, and may include port number such as :8080. Resource Path: /maps/api/geocode/json is the resource path of the API call. This path tends to use plural nouns and English- language descriptive words. Parameter: ?address=sanjose is a parameter that provides details for the service to filter, scope, or paginate the response data. Often, parameters are optional.
HTTP verb CRUD action POST create GET read PUT update PATCH update DELETE delete
A valid REST API request typically gets a 200 OK response whereas an invalid request gets a 404 Not Found Some REST APIs do not require authentication, but many do Requests and responses may use headers to pass information to form the service Some APIs use custom headers for authentication Some headers carry metadata to help define the request or response To know more about REST headers: https://www.ibm.com/ support/knowledgecenter/en/SSQP76_8.10.x/ com.ibm.odm.itoa.ref/topics/ref_rest_headers_codes.html
REST Payloads Body of request/response may include a payload that carries data to & from the service Data format of the payload: JSON or XML JSON: JavaScript Object Notation XML: eXtensible Markup Language
In JSON, the object is an unordered set of name- value pairs. An object begins with { (left brace) & ends with } (right brace) You can check the “Content-Type” header to know for certain what the service is sending
Getting started with REST APIs When documenting REST APIs, the trend is to use open standards such as OpenAPI(Swagger) or RAML to document requests, responses, headers & parameters. Read more about OpenAPI: https://swagger.io/ docs/specification/about/ Read more about RAML: https://raml.org/about- raml 1. Finding the API documentation 2. Figuring out authentication Read the documentation for the API
An endpoint is the URI where you send an HTTP request. The path of an endpoint can include notable information. e.g. to ensure compatibility, your API provider might specify a particular version of the API in the endpoint itself. An API provider can make an endpoint URI private and accessible only through a VPN or make it completely public on the Internet. You can learn which end points are available by reading the documentation. 3. Determining the end points
GET, POST, PUT, DELETE Many API documentation sites use color-coding for each verb. To compose a request: • determine the verb that reflects the action you want to perform • determine the endpoint upon which you want to perform the action 4. Understanding REST API verbs
parameters help to scope, filter or clarify a request Pagination(returning pages of data from a request) is sometimes implemented by using query parameters in the URI e.g. • max: to specify max no. of items to return • &: used between 2 parameters 5. Understanding REST API parameters
When sending a request, data formats are aka payloads. e.g. JSON, XML For each data format, the data maybe contained in the body of the request POST, PUT, PATCH requests typically include data requests or optional parameters as part of the request. GET responses nearly always include data. 6. Understanding REST API data formats
1. cURL: linux command line application 2. Postman: Chrome browser plugin & application 3. Python Requests: Python library for scripting 4. OpenAPI/Swagger: Dynamic API documentation Some REST API tools
References https://developer.cisco.com/learning/modules/rest-api- fundamentals/what-are-rest-apis/step/1 https://developer.cisco.com/learning/modules/rest-api- fundamentals/getting-started-rest-apis/step/1

API Basics

  • 1.
  • 2.
    SDN - Softwaredefined networking uses software to define/modify networks. Before SDN: the data plane and control plane were tied together as one.
  • 3.
    What SDN does: ona network device, data enters & leaves through the data plane decisions of what to do with the data are made by the control plane this allows network configuration & decisions to be completed through a remote control plane. to make SDN features on these devices accessible over the network, they are exposed through an API
  • 4.
    API: Application ProgrammingInterface REST: REpresentational State Transfer An API enables 2 pieces of software to communicate with each other.
  • 5.
    What is REST? RESTis an API framework built on HTTP when you combine REST and API, you see a simple service interface that enables applications or people to use HTTP protocol to request objects/information a REST API service sends all requests & responses over TCP/TLS connections using text
  • 6.
    A Look underthe hood at REST Protocol: http:// or https:// indicates whether the server host is open (http) or secured (https). Domain name: maps.googleapis.com is the domain name of the server or host that is providing the web service, and may include port number such as :8080. Resource Path: /maps/api/geocode/json is the resource path of the API call. This path tends to use plural nouns and English- language descriptive words. Parameter: ?address=sanjose is a parameter that provides details for the service to filter, scope, or paginate the response data. Often, parameters are optional.
  • 7.
    HTTP verb CRUDaction POST create GET read PUT update PATCH update DELETE delete
  • 8.
    A valid RESTAPI request typically gets a 200 OK response whereas an invalid request gets a 404 Not Found Some REST APIs do not require authentication, but many do Requests and responses may use headers to pass information to form the service Some APIs use custom headers for authentication Some headers carry metadata to help define the request or response To know more about REST headers: https://www.ibm.com/ support/knowledgecenter/en/SSQP76_8.10.x/ com.ibm.odm.itoa.ref/topics/ref_rest_headers_codes.html
  • 9.
    REST Payloads Body ofrequest/response may include a payload that carries data to & from the service Data format of the payload: JSON or XML JSON: JavaScript Object Notation XML: eXtensible Markup Language
  • 10.
    In JSON, theobject is an unordered set of name- value pairs. An object begins with { (left brace) & ends with } (right brace) You can check the “Content-Type” header to know for certain what the service is sending
  • 11.
    Getting started withREST APIs When documenting REST APIs, the trend is to use open standards such as OpenAPI(Swagger) or RAML to document requests, responses, headers & parameters. Read more about OpenAPI: https://swagger.io/ docs/specification/about/ Read more about RAML: https://raml.org/about- raml 1. Finding the API documentation 2. Figuring out authentication Read the documentation for the API
  • 12.
    An endpoint isthe URI where you send an HTTP request. The path of an endpoint can include notable information. e.g. to ensure compatibility, your API provider might specify a particular version of the API in the endpoint itself. An API provider can make an endpoint URI private and accessible only through a VPN or make it completely public on the Internet. You can learn which end points are available by reading the documentation. 3. Determining the end points
  • 13.
    GET, POST, PUT,DELETE Many API documentation sites use color-coding for each verb. To compose a request: • determine the verb that reflects the action you want to perform • determine the endpoint upon which you want to perform the action 4. Understanding REST API verbs
  • 14.
    parameters help toscope, filter or clarify a request Pagination(returning pages of data from a request) is sometimes implemented by using query parameters in the URI e.g. • max: to specify max no. of items to return • &: used between 2 parameters 5. Understanding REST API parameters
  • 15.
    When sending arequest, data formats are aka payloads. e.g. JSON, XML For each data format, the data maybe contained in the body of the request POST, PUT, PATCH requests typically include data requests or optional parameters as part of the request. GET responses nearly always include data. 6. Understanding REST API data formats
  • 16.
    1. cURL: linuxcommand line application 2. Postman: Chrome browser plugin & application 3. Python Requests: Python library for scripting 4. OpenAPI/Swagger: Dynamic API documentation Some REST API tools
  • 17.