DevNet Coding Camp: Coding Classes • Coding 100 - API Basics << You Are Here
• Coding 101: Calling REST APIs from Rest Client & Python • Coding 201 - Parsing JSON
Agenda • What is an API?
• What do they achieve?
• Why do all engineers should care about them?
• Understand the basic principles of REST.
• Understand JSON and XML.
• Understand the Structure and reading of a JSON string.
Requirements Tools Register with DevNet (http://developer.cisco.com)
DevNet Learning labs. Code Samples. Forum Access. Documentations.
A web browser (Chrome, Firefox, Safari) Text Editor (IDLE: installed by python, SublimeText: http://www.sublimetext.com/2 ) Postman (http://www.getpostman.com )
Expertise Basic Computer Skills Accessing web sites
API Definition • What does API Stand for?
• Application Programming Interface
• Definition of API • API consists of a set of rules describing how one application can interact with another, and the
mechanisms that allow such interaction to happen.
• Quick Demo
Common API Types • REST
• Representational State Transfer • Communicates over HTTP • Uses common HTTP verbs (GET, POST, PUT, DELETE) to extract data from server • Returns data in different format per request ( XML, JSON)
• SOAP
• Simple Object Access Protocol • Uses XML Information Set for its message format • Communicates over HTTP, SMTP, TCP, UDP • Publishes its API in machine readable format
• Language Based
• JAVA, Python, C • Generally more specialized, often faster, more complex for complex operations
REST – Request What do you need to know
• Uri: http://maps.googleapis.com/maps/api/geocode/json?address=sanjose
• Client Request • Header: • Content-Type: application/json or application/xml • Authorization: API Key
• Action • Get: Retrieve Data. • Post: Create new Record. • Put: Update a Record, if it does not exist, Create it. • Delete: Remove Record.
Server Resources Parameters
REST – Response What do you need to know
• Code • 200 - OK • 400 - The request was invalid or cannot be otherwise served. • 401 - Authentication credentials were missing or incorrect. • 403 - The request is understood, but it has been refused or access is not allowed. • 500 - Something went wrong on the server. • 503 - Server is overloaded with requests. Try again later.
• Content
• Can often return the same data in different formats per request • XML • JSON
REST – Response Data Format
• URI: http://maps.googleapis.com/maps/api/geocode • JSON XML
Postman Using POSTMAN to make API Calls
1. Start Postman (Plugin or App) 2. Specify Uri and Select Action
3. Hit ”URL Params” to pass parameters to API
4. Hit “Headers” to specify any authentication or MIME Types