SlideShare una empresa de Scribd logo
1 de 33
Coding Skills 101: How to
call REST APIs from
Python
Amanda Whaley – DevNet Community Manager
amwhaley@cisco.com
@mandywhaley
Agenda
• Who is this session for?
• REST Web Service Basics
• Try the APIC-EM APIs from
Postman
• Python Environment Setup
• Python Examples
• NEXT UI Toolkit
Who is Coding 101 for?
New coders
Returning coders
NetOps
DevOps
Congratulations! You have learned:
4
• REST Web Service Basics
• Anatomy of a REST API Request
• GET and POST
• How to call the APIC-EM APIs from Postman
• How to call REST APIs from Python
• Requests Library
Disclaimer: Sample Code vs. Real Code
5
The examples and code in this presentation are for Learning and
Educational purposes.
The samples were created with the goals of clarity and ease of
understanding.
If you are writing code for a real application, you would write the code
in a more efficient and structured style.
Follow along with the Learning Lab
6
• Login with DevNet/Cisco.com ID
• Coding 101 Lab
• Coding 102 Lab
• Taking it further: Coding 201-207 + APIC-EM Learning Labs
Follow Coding 102 instructions to setup your system
• Chrome
• A text editor (text wrangler, notepad ++, sublime text etc.)
• Postman REST Client -- http://www.getpostman.com/
• Python
• Go to command prompt and type python3 – did it work?
• http://learnpythonthehardway.org/book/ex0.html
• Python Requests library -- http://docs.python-requests.org
https://learninglabs.cisco.com
DevNet APIC-EM Always On Sandbox
7
Always there for you to use…
• Register on Cisco DevNet (http://developer.cisco.com ) to get the latest
information about APIs as they are release
• You can use the Always-On APIC-EM Sandbox at anytime
• You can use https://learninglabs.cisco.com at anytime
https://sandboxapic.cisco.com/
DevNet GitHub
8
coding-skills-sample-code repository
• All the code for this session
• All the code for all of the Coding Skills Learning Labs
https://github.com/CiscoDevNet
So what is a REST Web Service?
9
What is a Web Service?
– A way for two systems to communicate through a defined interface.
– Two major types of Web Services – REST or SOAP
What is a REST Web Service?
– REST is an architecture style for designing networked applications.
– A REST web service is a web service that is as easy to call as making an
HTTP request.
– RESTful interfaces often offer the CRUD operations
What is so great about REST?
10
• Hosts
• Devices
• Policies
• Applications
Easy to use:
• In mobile apps
• In console apps
• In web apps
How does this work?
Cisco APIC-EM REST APIs
How does this work?
8
3rd Party
App
3rd Party
App
Request
Response
Get Hosts
List of Hosts
Cisco APIC-EM
Cisco APIC-EM
APIC-EM Example: Get Hosts
12
3rd Party
App
GET http://{APIC-EMController}/api/v0/host/{start}/{no. rec}
List of Hosts returned in JSON
Cisco APIC-EM
APIC-EM Learning labs
Application Policy Infrastructure Controller (APIC) Enterprise Module (EM)
Request
Response
Anatomy of a REST Request
13
Method
– GET, POST, PUT, DELETE
URL
– Example: http://{APIC-EMController}/api/v0/host/1/3
Authentication
– Basic HTTP, OAuth, none
Custom Headers
– HTTP Headers
– Example: Content-Type: application/json
Request Body
– JSON or XML containing data needed to complete request
JSON -- JavaScript Object Notation, is a lightweight text-based open standard designed for human-readable data
interchange.
Using the API Reference Documentation
Using the API Reference Documentation
And what is in the Response?
16
HTTP Status Codes
– http://www.w3.org/Protocols/HTTP/HTRESP.html
– 200 OK
– 201 Created
– 500 Internal Error
Headers
Body
– JSON
– XML
REST in Action: How can I try it?
17
HTTP clients can help you quickly test web services
 Postman - http://www.getpostman.com/
 Firefox RestClient - https://addons.mozilla.org/en-US/firefox/addon/restclient/
 Command Line using curl - http://curl.haxx.se/docs/httpscripting.html#GET
 SOAPUI
Many IDEs have consoles for testing REST Services built in
We are going to use Postman as an example.
REST Demo – Using Postman
18
REST Demo – Using Postman
19
REST Demo – Using Postman
20
 Get Hosts
– Method: GET
– URL: http://APIC-EMController/api/v0/host/{startIndex}/{recordsToReturn}
 Get Devices
– Method: GET
– URL: http://APIC-EMController/api/v0/network-device/{startIndex}/{recordsToReturn}
 Get Policies
– Method: GET
– URL: http://APIC-EMController/api/v0/policy/{startIndex}/{recordsToReturn}
 Get Applications
– Method: GET
– URL: http://APIC-EMController/api/v0/application/{startIndex}/{recordsToReturn}
REST DEMO – Using the POST or PUT Method
21
To send data to a REST service and either create or update data, you will need
to use POST or PUT.
Create Policy Example
– Method: POST
– URL: http://APIC-EMController/api/v0/policy
– Custom Headers: Content-Type: application/json
– Request Body: JSON that specifies details of new policy
What if the Content-Type header is missing?
What if there is a mistake in the JSON Request Body?
Handy tool for validating JSON -- http://jsonlint.com/
REST Demo – Using POST or PUT Method
22
If you didn't receive a 202 Accepted message, check the following:
 Is your URI correct?
 Did you choose the method to be Post?
 Did you remember to specify the Content-Type header as
application/json?
 Did you get a message indicating that the policy already exists?
 If so, try it again with a different port (please use only high ports) or host.
Wait that didn’t work!??!
 Verify that your new policy exists
 Delete the policy you created
Next Steps
Setup your Python Environment
25
See https://learninglabs.cisco.com : Coding 102 Set up your system instructions
A text editor
– Text Wrangler, Notepad++, Sublime Text, PyCharm Community Edition etc.
Python installed on your system
– Preinstalled on many Linux distributions and Mac OS
– Windows may need to install - http://python.org/download.
– You can check to see if it is installed by typing “python” at a command prompt.
Python Requests library
– http://docs.python-requests.org/en/latest/user/install/#install
 Here are some sites that can help you setup your system:
– https://wiki.python.org/moin/BeginnersGuide/NonProgrammers
– http://learnpythonthehardway.org/book/ex0.html
– http://www.codecademy.com/tracks/python
First REST call from Python
26
#import requests library
import requests
#specify URL
url = 'http://Your-API-EM-Controller/api/v0/host’
#Call REST API
response = requests.get(url)
#Print Response
print response.text
Source code file: apic-em1.py
Python Examples
27
Coding 102
– apic-em1.py – simple example to get list of hosts
– apic-em-helloworld.py – “hello world” type example to show list of devices
– learning-lab-basics.py – Retrieves device list and pretty prints JSON
– learning-lab-basics-step2.py – Retrieves network device list and parses JSON
to display networkDeviceId values
– learning-lab-basics-step3.py – Retrieves and lists all devices, hosts, policies
and configured applications
– learning-lab-create-policy.py – Shows how to create a new policy using the
POST Method
https://github.com/CiscoDevNet/coding-skills-sample-code
Download Sample Code
Python Examples
28
Create a Policy –
– Basic steps
– 1. Get Hosts
– 2. Get Policies
– 3. Create a new Policy
– 4. Get Policies again to show new one that was added
Use POST Method
Set Header
– Content-Type: application/json
What if policy already exists?
A unique combination of hostIP, policy name, and ports is required to add a new
policy.
Source code file: learning-lab-create-policy.py
 learninglabs.cisco.com
 Coding 201 – Coding 207
 Next steps with Python
 developer.cisco.com
 Youtube Videos
 Cisco DevNet Github
 Get your DevNet Loot reward points!
Where to go from here?
References
30
 http://learnpythonthehardway.org/book/
 http://docs.python-requests.org/en/latest/index.html
 https://wiki.python.org/moin/BeginnersGuide/NonProgrammers
 http://www.codecademy.com/tracks/python
 https://www.python.org/doc/
 http://www.pythonlearn.com/html-008/cfbook014.html
 http://www.soapui.org/Best-Practices/understanding-rest-headers-and-parameters.html
 http://www.w3schools.com/jQuery/
 http://api.jquery.com/
Coding Classes all Week in the DevNet Zone
https://developer.cisco.com/site/DevNetZone/
Monday Tuesday Wednesday
8-9 am Coding 101 11- 12 pm Coding 203 10-11 am Coding 201
9-10 am Coding 101 1:30 -1 pm Coding 201
Workshop
11- 12 pm Coding 101
12 – 1pm Coding 201 2:30- 3 pm Coding 101
Workshop
11:30 -12 Coding 201
Workshop
1- 2 pm Coding 203 12 -1 pm Coding 210
2:30-3 Coding 101
Workshop
2:30- 3 pm Coding 203
Workshop
2-3 pm Coding 210
About Me
Amanda Whaley
• DevNet Community Manager
• amwhaley@cisco.com
• @mandywhaley
• Lives in Austin, TX.
• developer.cisco.com
• learninglabs.cisco.com
“Those who never fail
are those who never
try.”
-- Ilka Chase
Thank you

Más contenido relacionado

La actualidad más candente

Building Awesome APIs with Lumen
Building Awesome APIs with LumenBuilding Awesome APIs with Lumen
Building Awesome APIs with LumenKit Brennan
 
Ruby HTTP clients comparison
Ruby HTTP clients comparisonRuby HTTP clients comparison
Ruby HTTP clients comparisonHiroshi Nakamura
 
40+ tips to use Postman more efficiently
40+ tips to use Postman more efficiently40+ tips to use Postman more efficiently
40+ tips to use Postman more efficientlypostmanclient
 
A Brief History of OWIN
A Brief History of OWINA Brief History of OWIN
A Brief History of OWINRyan Riley
 
Regex Considered Harmful: Use Rosie Pattern Language Instead
Regex Considered Harmful: Use Rosie Pattern Language InsteadRegex Considered Harmful: Use Rosie Pattern Language Instead
Regex Considered Harmful: Use Rosie Pattern Language InsteadAll Things Open
 
An Introduction to Solr
An Introduction to SolrAn Introduction to Solr
An Introduction to Solrtomhill
 
REST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterREST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterSachin G Kulkarni
 
Understanding and testing restful web services
Understanding and testing restful web servicesUnderstanding and testing restful web services
Understanding and testing restful web servicesmwinteringham
 
Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)Postman
 
Ruby Projects and Libraries
Ruby Projects and LibrariesRuby Projects and Libraries
Ruby Projects and LibrariesVorleak Chy
 
Laravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingLaravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingChristopher Pecoraro
 
vienna.js - Automatic testing of (RESTful) API documentation
vienna.js - Automatic testing of (RESTful) API documentationvienna.js - Automatic testing of (RESTful) API documentation
vienna.js - Automatic testing of (RESTful) API documentationRouven Weßling
 
What's new in Rails 4
What's new in Rails 4What's new in Rails 4
What's new in Rails 4Lucas Caton
 
Google App Engine With Java And Groovy
Google App Engine With Java And GroovyGoogle App Engine With Java And Groovy
Google App Engine With Java And GroovyKen Kousen
 

La actualidad más candente (20)

REST API Laravel
REST API LaravelREST API Laravel
REST API Laravel
 
Building Awesome APIs with Lumen
Building Awesome APIs with LumenBuilding Awesome APIs with Lumen
Building Awesome APIs with Lumen
 
Ruby HTTP clients comparison
Ruby HTTP clients comparisonRuby HTTP clients comparison
Ruby HTTP clients comparison
 
F# on the Web
F# on the WebF# on the Web
F# on the Web
 
40+ tips to use Postman more efficiently
40+ tips to use Postman more efficiently40+ tips to use Postman more efficiently
40+ tips to use Postman more efficiently
 
A Brief History of OWIN
A Brief History of OWINA Brief History of OWIN
A Brief History of OWIN
 
Building a chatbot – step by step
Building a chatbot – step by stepBuilding a chatbot – step by step
Building a chatbot – step by step
 
Ruby HTTP clients
Ruby HTTP clientsRuby HTTP clients
Ruby HTTP clients
 
Regex Considered Harmful: Use Rosie Pattern Language Instead
Regex Considered Harmful: Use Rosie Pattern Language InsteadRegex Considered Harmful: Use Rosie Pattern Language Instead
Regex Considered Harmful: Use Rosie Pattern Language Instead
 
An Introduction to Solr
An Introduction to SolrAn Introduction to Solr
An Introduction to Solr
 
REST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterREST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in Codeigniter
 
Understanding and testing restful web services
Understanding and testing restful web servicesUnderstanding and testing restful web services
Understanding and testing restful web services
 
Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)
 
Ruby Projects and Libraries
Ruby Projects and LibrariesRuby Projects and Libraries
Ruby Projects and Libraries
 
Laravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingLaravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routing
 
vienna.js - Automatic testing of (RESTful) API documentation
vienna.js - Automatic testing of (RESTful) API documentationvienna.js - Automatic testing of (RESTful) API documentation
vienna.js - Automatic testing of (RESTful) API documentation
 
What's new in Rails 4
What's new in Rails 4What's new in Rails 4
What's new in Rails 4
 
Intro to PSGI and Plack
Intro to PSGI and PlackIntro to PSGI and Plack
Intro to PSGI and Plack
 
2012: ql.io and Node.js
2012: ql.io and Node.js2012: ql.io and Node.js
2012: ql.io and Node.js
 
Google App Engine With Java And Groovy
Google App Engine With Java And GroovyGoogle App Engine With Java And Groovy
Google App Engine With Java And Groovy
 

Destacado

The Basic Introduction of Open vSwitch
The Basic Introduction of Open vSwitchThe Basic Introduction of Open vSwitch
The Basic Introduction of Open vSwitchTe-Yen Liu
 
Automating with NX-OS: Let's Get Started!
Automating with NX-OS: Let's Get Started!Automating with NX-OS: Let's Get Started!
Automating with NX-OS: Let's Get Started!Cisco DevNet
 
Reliable Python REST API (by Volodymyr Hotsyk) - Web Back-End Tech Hangout - ...
Reliable Python REST API (by Volodymyr Hotsyk) - Web Back-End Tech Hangout - ...Reliable Python REST API (by Volodymyr Hotsyk) - Web Back-End Tech Hangout - ...
Reliable Python REST API (by Volodymyr Hotsyk) - Web Back-End Tech Hangout - ...Innovecs
 
Python RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsPython RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsSolution4Future
 
How to Build Advanced Voice Assistants and Chatbots
How to Build Advanced Voice Assistants and ChatbotsHow to Build Advanced Voice Assistants and Chatbots
How to Build Advanced Voice Assistants and ChatbotsCisco DevNet
 
DEVNET-2002 Coding 201: Coding Skills 201: Going Further with REST and Python...
DEVNET-2002	Coding 201: Coding Skills 201: Going Further with REST and Python...DEVNET-2002	Coding 201: Coding Skills 201: Going Further with REST and Python...
DEVNET-2002 Coding 201: Coding Skills 201: Going Further with REST and Python...Cisco DevNet
 
Developing RESTful Web APIs with Python, Flask and MongoDB
Developing RESTful Web APIs with Python, Flask and MongoDBDeveloping RESTful Web APIs with Python, Flask and MongoDB
Developing RESTful Web APIs with Python, Flask and MongoDBNicola Iarocci
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to PythonKHNOG
 
Understanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple StepsUnderstanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple StepsTessa Mero
 
Bidirectional Forwarding Detection (BFD)
Bidirectional Forwarding Detection (BFD) Bidirectional Forwarding Detection (BFD)
Bidirectional Forwarding Detection (BFD) KHNOG
 
Network Mapper (NMAP)
Network Mapper (NMAP)Network Mapper (NMAP)
Network Mapper (NMAP)KHNOG
 
Open-E DSS V7 Active-Active Load Balanced iSCSI HA Cluster (with bonding)
Open-E DSS V7 Active-Active Load Balanced iSCSI HA Cluster (with bonding)Open-E DSS V7 Active-Active Load Balanced iSCSI HA Cluster (with bonding)
Open-E DSS V7 Active-Active Load Balanced iSCSI HA Cluster (with bonding)open-e
 
Red Hat Storage Day Seattle: Why Software-Defined Storage Matters
Red Hat Storage Day Seattle: Why Software-Defined Storage MattersRed Hat Storage Day Seattle: Why Software-Defined Storage Matters
Red Hat Storage Day Seattle: Why Software-Defined Storage MattersRed_Hat_Storage
 
Policy Based Routing (PBR)
Policy Based Routing (PBR)Policy Based Routing (PBR)
Policy Based Routing (PBR)KHNOG
 
Routing Implementation - Cisco vs. Mikrotik
Routing Implementation - Cisco vs. MikrotikRouting Implementation - Cisco vs. Mikrotik
Routing Implementation - Cisco vs. MikrotikKHNOG
 
Swift Architecture and Practice, by Alex Yang
Swift Architecture and Practice, by Alex YangSwift Architecture and Practice, by Alex Yang
Swift Architecture and Practice, by Alex YangHui Cheng
 

Destacado (20)

The Basic Introduction of Open vSwitch
The Basic Introduction of Open vSwitchThe Basic Introduction of Open vSwitch
The Basic Introduction of Open vSwitch
 
Automating with NX-OS: Let's Get Started!
Automating with NX-OS: Let's Get Started!Automating with NX-OS: Let's Get Started!
Automating with NX-OS: Let's Get Started!
 
Rest api with Python
Rest api with PythonRest api with Python
Rest api with Python
 
Reliable Python REST API (by Volodymyr Hotsyk) - Web Back-End Tech Hangout - ...
Reliable Python REST API (by Volodymyr Hotsyk) - Web Back-End Tech Hangout - ...Reliable Python REST API (by Volodymyr Hotsyk) - Web Back-End Tech Hangout - ...
Reliable Python REST API (by Volodymyr Hotsyk) - Web Back-End Tech Hangout - ...
 
Python RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsPython RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutions
 
How to Build Advanced Voice Assistants and Chatbots
How to Build Advanced Voice Assistants and ChatbotsHow to Build Advanced Voice Assistants and Chatbots
How to Build Advanced Voice Assistants and Chatbots
 
DEVNET-2002 Coding 201: Coding Skills 201: Going Further with REST and Python...
DEVNET-2002	Coding 201: Coding Skills 201: Going Further with REST and Python...DEVNET-2002	Coding 201: Coding Skills 201: Going Further with REST and Python...
DEVNET-2002 Coding 201: Coding Skills 201: Going Further with REST and Python...
 
Developing RESTful Web APIs with Python, Flask and MongoDB
Developing RESTful Web APIs with Python, Flask and MongoDBDeveloping RESTful Web APIs with Python, Flask and MongoDB
Developing RESTful Web APIs with Python, Flask and MongoDB
 
JSON and REST
JSON and RESTJSON and REST
JSON and REST
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Understanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple StepsUnderstanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple Steps
 
Python101
Python101Python101
Python101
 
Bidirectional Forwarding Detection (BFD)
Bidirectional Forwarding Detection (BFD) Bidirectional Forwarding Detection (BFD)
Bidirectional Forwarding Detection (BFD)
 
Network Mapper (NMAP)
Network Mapper (NMAP)Network Mapper (NMAP)
Network Mapper (NMAP)
 
Open-E DSS V7 Active-Active Load Balanced iSCSI HA Cluster (with bonding)
Open-E DSS V7 Active-Active Load Balanced iSCSI HA Cluster (with bonding)Open-E DSS V7 Active-Active Load Balanced iSCSI HA Cluster (with bonding)
Open-E DSS V7 Active-Active Load Balanced iSCSI HA Cluster (with bonding)
 
Pycon 2008: Python Command-line Tools *Nix
Pycon 2008:  Python Command-line Tools *NixPycon 2008:  Python Command-line Tools *Nix
Pycon 2008: Python Command-line Tools *Nix
 
Red Hat Storage Day Seattle: Why Software-Defined Storage Matters
Red Hat Storage Day Seattle: Why Software-Defined Storage MattersRed Hat Storage Day Seattle: Why Software-Defined Storage Matters
Red Hat Storage Day Seattle: Why Software-Defined Storage Matters
 
Policy Based Routing (PBR)
Policy Based Routing (PBR)Policy Based Routing (PBR)
Policy Based Routing (PBR)
 
Routing Implementation - Cisco vs. Mikrotik
Routing Implementation - Cisco vs. MikrotikRouting Implementation - Cisco vs. Mikrotik
Routing Implementation - Cisco vs. Mikrotik
 
Swift Architecture and Practice, by Alex Yang
Swift Architecture and Practice, by Alex YangSwift Architecture and Practice, by Alex Yang
Swift Architecture and Practice, by Alex Yang
 

Similar a DEVNET-1001 Coding 101: How to Call REST APIs from a REST Client and Python

Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.Mario Cardinal
 
Designing RESTful APIs
Designing RESTful APIsDesigning RESTful APIs
Designing RESTful APIsanandology
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiTiago Knoch
 
Rest api titouan benoit
Rest api   titouan benoitRest api   titouan benoit
Rest api titouan benoitTitouan BENOIT
 
Building Beautiful REST APIs with ASP.NET Core
Building Beautiful REST APIs with ASP.NET CoreBuilding Beautiful REST APIs with ASP.NET Core
Building Beautiful REST APIs with ASP.NET CoreStormpath
 
(ATS6-PLAT04) Query service
(ATS6-PLAT04) Query service (ATS6-PLAT04) Query service
(ATS6-PLAT04) Query service BIOVIA
 
Getting to Grips with RESTful APIs
Getting to Grips with RESTful APIsGetting to Grips with RESTful APIs
Getting to Grips with RESTful APIsPetko Mikhailov
 
RESTful APIs and SBCs
RESTful APIs and SBCsRESTful APIs and SBCs
RESTful APIs and SBCsAlan Percy
 
Resting on your laurels will get you powned
Resting on your laurels will get you pownedResting on your laurels will get you powned
Resting on your laurels will get you pownedDinis Cruz
 
Resting with OroCRM Webinar
Resting with OroCRM WebinarResting with OroCRM Webinar
Resting with OroCRM WebinarOro Inc.
 
Building Your First App with MongoDB
Building Your First App with MongoDBBuilding Your First App with MongoDB
Building Your First App with MongoDBMongoDB
 
07 restful webservices design
07 restful webservices design07 restful webservices design
07 restful webservices designAhmed Elbassel
 
Test in Rest. API testing with the help of Rest Assured.
Test in Rest. API testing with the help of  Rest Assured.Test in Rest. API testing with the help of  Rest Assured.
Test in Rest. API testing with the help of Rest Assured.Artem Korchevyi
 
API testing with the help of Rest Assured
API testing with the help of  Rest Assured API testing with the help of  Rest Assured
API testing with the help of Rest Assured Artem Korchevyi
 
High quality ap is with api platform
High quality ap is with api platformHigh quality ap is with api platform
High quality ap is with api platformNelson Kopliku
 
PHP on Windows 2008
PHP on Windows 2008PHP on Windows 2008
PHP on Windows 2008jorke
 

Similar a DEVNET-1001 Coding 101: How to Call REST APIs from a REST Client and Python (20)

Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.
 
Designing RESTful APIs
Designing RESTful APIsDesigning RESTful APIs
Designing RESTful APIs
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web api
 
POSTMAN.pptx
POSTMAN.pptxPOSTMAN.pptx
POSTMAN.pptx
 
Rest api titouan benoit
Rest api   titouan benoitRest api   titouan benoit
Rest api titouan benoit
 
Building Beautiful REST APIs with ASP.NET Core
Building Beautiful REST APIs with ASP.NET CoreBuilding Beautiful REST APIs with ASP.NET Core
Building Beautiful REST APIs with ASP.NET Core
 
REST API Basics
REST API BasicsREST API Basics
REST API Basics
 
(ATS6-PLAT04) Query service
(ATS6-PLAT04) Query service (ATS6-PLAT04) Query service
(ATS6-PLAT04) Query service
 
Getting to Grips with RESTful APIs
Getting to Grips with RESTful APIsGetting to Grips with RESTful APIs
Getting to Grips with RESTful APIs
 
Web api
Web apiWeb api
Web api
 
RESTful APIs and SBCs
RESTful APIs and SBCsRESTful APIs and SBCs
RESTful APIs and SBCs
 
Resting on your laurels will get you powned
Resting on your laurels will get you pownedResting on your laurels will get you powned
Resting on your laurels will get you powned
 
RESTful APIs and SBCs
RESTful APIs and SBCsRESTful APIs and SBCs
RESTful APIs and SBCs
 
Resting with OroCRM Webinar
Resting with OroCRM WebinarResting with OroCRM Webinar
Resting with OroCRM Webinar
 
Building Your First App with MongoDB
Building Your First App with MongoDBBuilding Your First App with MongoDB
Building Your First App with MongoDB
 
07 restful webservices design
07 restful webservices design07 restful webservices design
07 restful webservices design
 
Test in Rest. API testing with the help of Rest Assured.
Test in Rest. API testing with the help of  Rest Assured.Test in Rest. API testing with the help of  Rest Assured.
Test in Rest. API testing with the help of Rest Assured.
 
API testing with the help of Rest Assured
API testing with the help of  Rest Assured API testing with the help of  Rest Assured
API testing with the help of Rest Assured
 
High quality ap is with api platform
High quality ap is with api platformHigh quality ap is with api platform
High quality ap is with api platform
 
PHP on Windows 2008
PHP on Windows 2008PHP on Windows 2008
PHP on Windows 2008
 

Más de Cisco DevNet

How to Contribute to Ansible
How to Contribute to AnsibleHow to Contribute to Ansible
How to Contribute to AnsibleCisco DevNet
 
Rome 2017: Building advanced voice assistants and chat bots
Rome 2017: Building advanced voice assistants and chat botsRome 2017: Building advanced voice assistants and chat bots
Rome 2017: Building advanced voice assistants and chat botsCisco DevNet
 
Cisco Spark and Tropo and the Programmable Web
Cisco Spark and Tropo and the Programmable WebCisco Spark and Tropo and the Programmable Web
Cisco Spark and Tropo and the Programmable WebCisco DevNet
 
Device Programmability with Cisco Plug-n-Play Solution
Device Programmability with Cisco Plug-n-Play SolutionDevice Programmability with Cisco Plug-n-Play Solution
Device Programmability with Cisco Plug-n-Play SolutionCisco DevNet
 
Building a WiFi Hotspot with NodeJS: Cisco Meraki - ExCap API
Building a WiFi Hotspot with NodeJS: Cisco Meraki - ExCap APIBuilding a WiFi Hotspot with NodeJS: Cisco Meraki - ExCap API
Building a WiFi Hotspot with NodeJS: Cisco Meraki - ExCap APICisco DevNet
 
Application Visibility and Experience through Flexible Netflow
Application Visibility and Experience through Flexible NetflowApplication Visibility and Experience through Flexible Netflow
Application Visibility and Experience through Flexible NetflowCisco DevNet
 
WAN Automation Engine API Deep Dive
WAN Automation Engine API Deep DiveWAN Automation Engine API Deep Dive
WAN Automation Engine API Deep DiveCisco DevNet
 
Cisco's Open Device Programmability Strategy: Open Discussion
Cisco's Open Device Programmability Strategy: Open DiscussionCisco's Open Device Programmability Strategy: Open Discussion
Cisco's Open Device Programmability Strategy: Open DiscussionCisco DevNet
 
Open Device Programmability: Hands-on Intro to RESTCONF (and a bit of NETCONF)
Open Device Programmability: Hands-on Intro to RESTCONF (and a bit of NETCONF)Open Device Programmability: Hands-on Intro to RESTCONF (and a bit of NETCONF)
Open Device Programmability: Hands-on Intro to RESTCONF (and a bit of NETCONF)Cisco DevNet
 
NETCONF & YANG Enablement of Network Devices
NETCONF & YANG Enablement of Network DevicesNETCONF & YANG Enablement of Network Devices
NETCONF & YANG Enablement of Network DevicesCisco DevNet
 
UCS Management APIs A Technical Deep Dive
UCS Management APIs A Technical Deep DiveUCS Management APIs A Technical Deep Dive
UCS Management APIs A Technical Deep DiveCisco DevNet
 
OpenStack Enabling DevOps
OpenStack Enabling DevOpsOpenStack Enabling DevOps
OpenStack Enabling DevOpsCisco DevNet
 
NetDevOps for the Network Dude: How to get started with API's, Ansible and Py...
NetDevOps for the Network Dude: How to get started with API's, Ansible and Py...NetDevOps for the Network Dude: How to get started with API's, Ansible and Py...
NetDevOps for the Network Dude: How to get started with API's, Ansible and Py...Cisco DevNet
 
Getting Started: Developing Tropo Applications
Getting Started: Developing Tropo ApplicationsGetting Started: Developing Tropo Applications
Getting Started: Developing Tropo ApplicationsCisco DevNet
 
Cisco Spark & Tropo API Workshop
Cisco Spark & Tropo API WorkshopCisco Spark & Tropo API Workshop
Cisco Spark & Tropo API WorkshopCisco DevNet
 
Coding 102 REST API Basics Using Spark
Coding 102 REST API Basics Using SparkCoding 102 REST API Basics Using Spark
Coding 102 REST API Basics Using SparkCisco DevNet
 
Cisco APIs: An Interactive Assistant for the Web2Day Developer Conference
Cisco APIs: An Interactive Assistant for the Web2Day Developer ConferenceCisco APIs: An Interactive Assistant for the Web2Day Developer Conference
Cisco APIs: An Interactive Assistant for the Web2Day Developer ConferenceCisco DevNet
 
DevNet Express - Spark & Tropo API - Lisbon May 2016
DevNet Express - Spark & Tropo API - Lisbon May 2016DevNet Express - Spark & Tropo API - Lisbon May 2016
DevNet Express - Spark & Tropo API - Lisbon May 2016Cisco DevNet
 
DevNet @TAG - Spark & Tropo APIs - Milan/Rome May 2016
DevNet @TAG - Spark & Tropo APIs - Milan/Rome May 2016DevNet @TAG - Spark & Tropo APIs - Milan/Rome May 2016
DevNet @TAG - Spark & Tropo APIs - Milan/Rome May 2016Cisco DevNet
 
Choosing PaaS: Cisco and Open Source Options: an overview
Choosing PaaS:  Cisco and Open Source Options: an overviewChoosing PaaS:  Cisco and Open Source Options: an overview
Choosing PaaS: Cisco and Open Source Options: an overviewCisco DevNet
 

Más de Cisco DevNet (20)

How to Contribute to Ansible
How to Contribute to AnsibleHow to Contribute to Ansible
How to Contribute to Ansible
 
Rome 2017: Building advanced voice assistants and chat bots
Rome 2017: Building advanced voice assistants and chat botsRome 2017: Building advanced voice assistants and chat bots
Rome 2017: Building advanced voice assistants and chat bots
 
Cisco Spark and Tropo and the Programmable Web
Cisco Spark and Tropo and the Programmable WebCisco Spark and Tropo and the Programmable Web
Cisco Spark and Tropo and the Programmable Web
 
Device Programmability with Cisco Plug-n-Play Solution
Device Programmability with Cisco Plug-n-Play SolutionDevice Programmability with Cisco Plug-n-Play Solution
Device Programmability with Cisco Plug-n-Play Solution
 
Building a WiFi Hotspot with NodeJS: Cisco Meraki - ExCap API
Building a WiFi Hotspot with NodeJS: Cisco Meraki - ExCap APIBuilding a WiFi Hotspot with NodeJS: Cisco Meraki - ExCap API
Building a WiFi Hotspot with NodeJS: Cisco Meraki - ExCap API
 
Application Visibility and Experience through Flexible Netflow
Application Visibility and Experience through Flexible NetflowApplication Visibility and Experience through Flexible Netflow
Application Visibility and Experience through Flexible Netflow
 
WAN Automation Engine API Deep Dive
WAN Automation Engine API Deep DiveWAN Automation Engine API Deep Dive
WAN Automation Engine API Deep Dive
 
Cisco's Open Device Programmability Strategy: Open Discussion
Cisco's Open Device Programmability Strategy: Open DiscussionCisco's Open Device Programmability Strategy: Open Discussion
Cisco's Open Device Programmability Strategy: Open Discussion
 
Open Device Programmability: Hands-on Intro to RESTCONF (and a bit of NETCONF)
Open Device Programmability: Hands-on Intro to RESTCONF (and a bit of NETCONF)Open Device Programmability: Hands-on Intro to RESTCONF (and a bit of NETCONF)
Open Device Programmability: Hands-on Intro to RESTCONF (and a bit of NETCONF)
 
NETCONF & YANG Enablement of Network Devices
NETCONF & YANG Enablement of Network DevicesNETCONF & YANG Enablement of Network Devices
NETCONF & YANG Enablement of Network Devices
 
UCS Management APIs A Technical Deep Dive
UCS Management APIs A Technical Deep DiveUCS Management APIs A Technical Deep Dive
UCS Management APIs A Technical Deep Dive
 
OpenStack Enabling DevOps
OpenStack Enabling DevOpsOpenStack Enabling DevOps
OpenStack Enabling DevOps
 
NetDevOps for the Network Dude: How to get started with API's, Ansible and Py...
NetDevOps for the Network Dude: How to get started with API's, Ansible and Py...NetDevOps for the Network Dude: How to get started with API's, Ansible and Py...
NetDevOps for the Network Dude: How to get started with API's, Ansible and Py...
 
Getting Started: Developing Tropo Applications
Getting Started: Developing Tropo ApplicationsGetting Started: Developing Tropo Applications
Getting Started: Developing Tropo Applications
 
Cisco Spark & Tropo API Workshop
Cisco Spark & Tropo API WorkshopCisco Spark & Tropo API Workshop
Cisco Spark & Tropo API Workshop
 
Coding 102 REST API Basics Using Spark
Coding 102 REST API Basics Using SparkCoding 102 REST API Basics Using Spark
Coding 102 REST API Basics Using Spark
 
Cisco APIs: An Interactive Assistant for the Web2Day Developer Conference
Cisco APIs: An Interactive Assistant for the Web2Day Developer ConferenceCisco APIs: An Interactive Assistant for the Web2Day Developer Conference
Cisco APIs: An Interactive Assistant for the Web2Day Developer Conference
 
DevNet Express - Spark & Tropo API - Lisbon May 2016
DevNet Express - Spark & Tropo API - Lisbon May 2016DevNet Express - Spark & Tropo API - Lisbon May 2016
DevNet Express - Spark & Tropo API - Lisbon May 2016
 
DevNet @TAG - Spark & Tropo APIs - Milan/Rome May 2016
DevNet @TAG - Spark & Tropo APIs - Milan/Rome May 2016DevNet @TAG - Spark & Tropo APIs - Milan/Rome May 2016
DevNet @TAG - Spark & Tropo APIs - Milan/Rome May 2016
 
Choosing PaaS: Cisco and Open Source Options: an overview
Choosing PaaS:  Cisco and Open Source Options: an overviewChoosing PaaS:  Cisco and Open Source Options: an overview
Choosing PaaS: Cisco and Open Source Options: an overview
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 

Último (20)

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 

DEVNET-1001 Coding 101: How to Call REST APIs from a REST Client and Python

  • 1. Coding Skills 101: How to call REST APIs from Python Amanda Whaley – DevNet Community Manager amwhaley@cisco.com @mandywhaley
  • 2. Agenda • Who is this session for? • REST Web Service Basics • Try the APIC-EM APIs from Postman • Python Environment Setup • Python Examples • NEXT UI Toolkit
  • 3. Who is Coding 101 for? New coders Returning coders NetOps DevOps
  • 4. Congratulations! You have learned: 4 • REST Web Service Basics • Anatomy of a REST API Request • GET and POST • How to call the APIC-EM APIs from Postman • How to call REST APIs from Python • Requests Library
  • 5. Disclaimer: Sample Code vs. Real Code 5 The examples and code in this presentation are for Learning and Educational purposes. The samples were created with the goals of clarity and ease of understanding. If you are writing code for a real application, you would write the code in a more efficient and structured style.
  • 6. Follow along with the Learning Lab 6 • Login with DevNet/Cisco.com ID • Coding 101 Lab • Coding 102 Lab • Taking it further: Coding 201-207 + APIC-EM Learning Labs Follow Coding 102 instructions to setup your system • Chrome • A text editor (text wrangler, notepad ++, sublime text etc.) • Postman REST Client -- http://www.getpostman.com/ • Python • Go to command prompt and type python3 – did it work? • http://learnpythonthehardway.org/book/ex0.html • Python Requests library -- http://docs.python-requests.org https://learninglabs.cisco.com
  • 7. DevNet APIC-EM Always On Sandbox 7 Always there for you to use… • Register on Cisco DevNet (http://developer.cisco.com ) to get the latest information about APIs as they are release • You can use the Always-On APIC-EM Sandbox at anytime • You can use https://learninglabs.cisco.com at anytime https://sandboxapic.cisco.com/
  • 8. DevNet GitHub 8 coding-skills-sample-code repository • All the code for this session • All the code for all of the Coding Skills Learning Labs https://github.com/CiscoDevNet
  • 9. So what is a REST Web Service? 9 What is a Web Service? – A way for two systems to communicate through a defined interface. – Two major types of Web Services – REST or SOAP What is a REST Web Service? – REST is an architecture style for designing networked applications. – A REST web service is a web service that is as easy to call as making an HTTP request. – RESTful interfaces often offer the CRUD operations
  • 10. What is so great about REST? 10 • Hosts • Devices • Policies • Applications Easy to use: • In mobile apps • In console apps • In web apps How does this work? Cisco APIC-EM REST APIs
  • 11. How does this work? 8 3rd Party App 3rd Party App Request Response Get Hosts List of Hosts Cisco APIC-EM Cisco APIC-EM
  • 12. APIC-EM Example: Get Hosts 12 3rd Party App GET http://{APIC-EMController}/api/v0/host/{start}/{no. rec} List of Hosts returned in JSON Cisco APIC-EM APIC-EM Learning labs Application Policy Infrastructure Controller (APIC) Enterprise Module (EM) Request Response
  • 13. Anatomy of a REST Request 13 Method – GET, POST, PUT, DELETE URL – Example: http://{APIC-EMController}/api/v0/host/1/3 Authentication – Basic HTTP, OAuth, none Custom Headers – HTTP Headers – Example: Content-Type: application/json Request Body – JSON or XML containing data needed to complete request JSON -- JavaScript Object Notation, is a lightweight text-based open standard designed for human-readable data interchange.
  • 14. Using the API Reference Documentation
  • 15. Using the API Reference Documentation
  • 16. And what is in the Response? 16 HTTP Status Codes – http://www.w3.org/Protocols/HTTP/HTRESP.html – 200 OK – 201 Created – 500 Internal Error Headers Body – JSON – XML
  • 17. REST in Action: How can I try it? 17 HTTP clients can help you quickly test web services  Postman - http://www.getpostman.com/  Firefox RestClient - https://addons.mozilla.org/en-US/firefox/addon/restclient/  Command Line using curl - http://curl.haxx.se/docs/httpscripting.html#GET  SOAPUI Many IDEs have consoles for testing REST Services built in We are going to use Postman as an example.
  • 18. REST Demo – Using Postman 18
  • 19. REST Demo – Using Postman 19
  • 20. REST Demo – Using Postman 20  Get Hosts – Method: GET – URL: http://APIC-EMController/api/v0/host/{startIndex}/{recordsToReturn}  Get Devices – Method: GET – URL: http://APIC-EMController/api/v0/network-device/{startIndex}/{recordsToReturn}  Get Policies – Method: GET – URL: http://APIC-EMController/api/v0/policy/{startIndex}/{recordsToReturn}  Get Applications – Method: GET – URL: http://APIC-EMController/api/v0/application/{startIndex}/{recordsToReturn}
  • 21. REST DEMO – Using the POST or PUT Method 21 To send data to a REST service and either create or update data, you will need to use POST or PUT. Create Policy Example – Method: POST – URL: http://APIC-EMController/api/v0/policy – Custom Headers: Content-Type: application/json – Request Body: JSON that specifies details of new policy What if the Content-Type header is missing? What if there is a mistake in the JSON Request Body? Handy tool for validating JSON -- http://jsonlint.com/
  • 22. REST Demo – Using POST or PUT Method 22
  • 23. If you didn't receive a 202 Accepted message, check the following:  Is your URI correct?  Did you choose the method to be Post?  Did you remember to specify the Content-Type header as application/json?  Did you get a message indicating that the policy already exists?  If so, try it again with a different port (please use only high ports) or host. Wait that didn’t work!??!
  • 24.  Verify that your new policy exists  Delete the policy you created Next Steps
  • 25. Setup your Python Environment 25 See https://learninglabs.cisco.com : Coding 102 Set up your system instructions A text editor – Text Wrangler, Notepad++, Sublime Text, PyCharm Community Edition etc. Python installed on your system – Preinstalled on many Linux distributions and Mac OS – Windows may need to install - http://python.org/download. – You can check to see if it is installed by typing “python” at a command prompt. Python Requests library – http://docs.python-requests.org/en/latest/user/install/#install  Here are some sites that can help you setup your system: – https://wiki.python.org/moin/BeginnersGuide/NonProgrammers – http://learnpythonthehardway.org/book/ex0.html – http://www.codecademy.com/tracks/python
  • 26. First REST call from Python 26 #import requests library import requests #specify URL url = 'http://Your-API-EM-Controller/api/v0/host’ #Call REST API response = requests.get(url) #Print Response print response.text Source code file: apic-em1.py
  • 27. Python Examples 27 Coding 102 – apic-em1.py – simple example to get list of hosts – apic-em-helloworld.py – “hello world” type example to show list of devices – learning-lab-basics.py – Retrieves device list and pretty prints JSON – learning-lab-basics-step2.py – Retrieves network device list and parses JSON to display networkDeviceId values – learning-lab-basics-step3.py – Retrieves and lists all devices, hosts, policies and configured applications – learning-lab-create-policy.py – Shows how to create a new policy using the POST Method https://github.com/CiscoDevNet/coding-skills-sample-code Download Sample Code
  • 28. Python Examples 28 Create a Policy – – Basic steps – 1. Get Hosts – 2. Get Policies – 3. Create a new Policy – 4. Get Policies again to show new one that was added Use POST Method Set Header – Content-Type: application/json What if policy already exists? A unique combination of hostIP, policy name, and ports is required to add a new policy. Source code file: learning-lab-create-policy.py
  • 29.  learninglabs.cisco.com  Coding 201 – Coding 207  Next steps with Python  developer.cisco.com  Youtube Videos  Cisco DevNet Github  Get your DevNet Loot reward points! Where to go from here?
  • 30. References 30  http://learnpythonthehardway.org/book/  http://docs.python-requests.org/en/latest/index.html  https://wiki.python.org/moin/BeginnersGuide/NonProgrammers  http://www.codecademy.com/tracks/python  https://www.python.org/doc/  http://www.pythonlearn.com/html-008/cfbook014.html  http://www.soapui.org/Best-Practices/understanding-rest-headers-and-parameters.html  http://www.w3schools.com/jQuery/  http://api.jquery.com/
  • 31. Coding Classes all Week in the DevNet Zone https://developer.cisco.com/site/DevNetZone/ Monday Tuesday Wednesday 8-9 am Coding 101 11- 12 pm Coding 203 10-11 am Coding 201 9-10 am Coding 101 1:30 -1 pm Coding 201 Workshop 11- 12 pm Coding 101 12 – 1pm Coding 201 2:30- 3 pm Coding 101 Workshop 11:30 -12 Coding 201 Workshop 1- 2 pm Coding 203 12 -1 pm Coding 210 2:30-3 Coding 101 Workshop 2:30- 3 pm Coding 203 Workshop 2-3 pm Coding 210
  • 32. About Me Amanda Whaley • DevNet Community Manager • amwhaley@cisco.com • @mandywhaley • Lives in Austin, TX. • developer.cisco.com • learninglabs.cisco.com “Those who never fail are those who never try.” -- Ilka Chase

Notas del editor

  1. REST stands for Representational State Transfer. It relies on a stateless, client-server, cacheable communications protocol (ex. HTTP)
  2. http://www.json.org/
  3. Show what happens if you forget the Content-Type Header
  4. More info on requests library - http://docs.python-requests.org/en/latest/index.html