Coding Intro to APIs and REST

Similar documents
NXOS in the Real World Using NX-API REST

Get Hands On With DNA Center APIs for Managing Intent

Your API Toolbelt Tools and techniques for testing, monitoring, and troubleshooting REST API requests

Automation with Meraki Provisioning API

Hands On Exploration of NETCONF and YANG

RESTCONF Programmable Interface

Git, Atom, virtualenv, oh my! Learn about dev tools to live by!

Cisco IOS XR Programmability for Cloud-Scale Networking

Coding Getting Started with Python

Introduction to OpenConfig

DEVNET Introduction to Git. Ashley Roach Principal Engineer Evangelist

Black Box DCX3000 / DCX1000 Using the API

NetDevOps Style Configuration Management for the Network

Finesse APIs: Getting started with the REST APIs and XMPP events

Consuming Model-Driven Telemetry

Hybrid Cloud Automation using Cisco CloudCenter API

Automation and Programmability using Cisco Open NXOS and DevOps Tools

Managing Cisco UCS with the Python SDK

Integrating with ClearPass HTTP APIs

Hands-On with IoT Standards & Protocols

Cisco WAN Automation Engine (WAE) Network Programmability with Segment Routing

Getting Started with OpenStack

Empower your testing with Cisco Test Automation Solution Featuring pyats & Genie

Cisco Network Programmability for the Enterprise NPEN v1.0

Cisco Spark Widgets Technical drill down

CloudCenter for Developers

Magical Chatbots with Cisco Spark and IBM Watson

Spark SDK Video - Overview and Coding Demo

NIELSEN API PORTAL USER REGISTRATION GUIDE

2018 Cisco and/or its affiliates. All rights reserved. Cisco Public

Using OAuth 2.0 to Access ionbiz APIs

Cisco UCS Agentless Configuration Management Ansible or Microsoft DSC

Reviewing the API Documentation

Using the YANG Development Kit (YDK) with Cisco IOS XE

REST API Developer Preview

REST. Lecture BigData Analytics. Julian M. Kunkel. University of Hamburg / German Climate Computing Center (DKRZ)

Cisco Spark API Workshop

NETCONF Protocol. Restrictions for the NETCONF Protocol. Information About the NETCONF Protocol

Tour the latest Cisco Spark API features

APIs Assist Troubleshooting in Manufacturing

Kuber-what?! Learn about Kubernetes

Insights into your WLC with Wireless Streaming Telemetry

Oracle RESTful Services A Primer for Database Administrators

Who wants to be a millionaire? A class in creating your own cryptocurrency

PnP Deep Dive Hands-on with APIC-EM and Prime Infrastructure

NetDevOps for the Network Dude How to get started with API's, Ansible and Python

Salesforce IoT REST API Getting Started Guide

also supports JSON output format for specific commands.

WEB API. Nuki Home Solutions GmbH. Münzgrabenstraße 92/ Graz Austria F

An Introduction to Monitoring Encrypted Network Traffic with "Joy"

Optimizing the Usability of YANG Models for Network Automation

Cloud Mobility: Meraki Wireless & EMM

DevNet Workshop-Hands-on with CloudCenter and Jenkins

Cisco Spark Messaging APIs - Integration Platforms as a Service Real World Use-Cases

Getting Started With Containers

PSOACI Tetration Overview. Mike Herbert

Cisco Connected Mobile Experiences REST API Getting Started Guide, Release 10.2

ICE / TURN / STUN Tutorial

Understanding RESTful APIs and documenting them with Swagger. Presented by: Tanya Perelmuter Date: 06/18/2018

NSO in Brownfield: Fully Automated One-Click Reconciliation

An Introduction to Developing for Cisco Kinetic

WORKSHOP: from Zero to a Network Application with #golang

Using the Web Graphical User Interface

Writing REST APIs with OpenAPI and Swagger Ada

Deploying Cloud-Agnostic Applications with Cisco CloudCenter

HTTP, REST Web Services

Ipswitch: The New way of Network Monitoring and how to provide managed services to its customers

TRex Realistic Traffic Generator

Using the Web Graphical User Interface

BlackBerry AtHoc Networked Crisis Communication. BlackBerry AtHoc API Quick Start Guide

Introduction to RESTful Web Services. Presented by Steve Ives

Enabling Embedded Systems to access Internet Resources

Explore curl for FileMaker

Internet of Things Field Network Director

REST Web Services Objektumorientált szoftvertervezés Object-oriented software design

Tutorial: Building the Services Ecosystem

Protocols. Application Layer FTP, HTTP, SSH, IMAP. Transport Layer TCP, UDP. Internet Layer IP. Link Layer Ethernet, WiFi

Management Tools. Management Tools. About the Management GUI. About the CLI. This chapter contains the following sections:

SSH with Globus Auth

Usage of "OAuth2" policy action in CentraSite and Mediator

OpenDaylight as a Platform for Network Programmability FOSDEM, 3 February Charles Eckel, Cisco DevNet

Leveraging the Globus Platform in your Web Applications. GlobusWorld April 26, 2018 Greg Nawrocki

Real time Location Services Overview and Use cases

White paper irmc Redfish API

User Authentication APIs

CNIT 129S: Securing Web Applications. Ch 3: Web Application Technologies

StorageGRID Webscale 11.0 Tenant Administrator Guide

RESTful API Design APIs your consumers will love

Privacy Requirements Scoping

flask-jwt-simple Documentation

User Workspace Management

Cisco Container Platform

DatabaseRESTAPI

Catalyst 9K High Availability Lab

RKN 2015 Application Layer Short Summary

COMPUTER NETWORKS AND COMMUNICATION PROTOCOLS. Web Access: HTTP Mehmet KORKMAZ

WooCommerce REST API Integration. October 27, 2018

PAS for OpenEdge Support for JWT and OAuth Samples -

Sample Title. Dancing with the Magento 2 APIs. A guided tour of the API dance floor. DevelopersParadise 2016 / Opatija / Croatia

Machine Learning with Python

Transcription:

DEVNET-3607 Coding 1001 - Intro to APIs and REST Matthew DeNapoli DevNet Developer Evangelist

Cisco Spark How Questions? Use Cisco Spark to communicate with the speaker after the session 1. Find this session in the Cisco Live Mobile App 2. Click Join the Discussion 3. Install Spark or go directly to the space 4. Enter messages/questions in the space cs.co/ciscolivebot#devnet-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public

Agenda What is an API? APIs aren t scary you already use them Other APIs out there What is REST? A Look Under the Hood at REST? Some REST Examples REST API Tools

What are APIs?

APIs are a way for two pieces of software to talk to each other the interface for software systems sets of requirements that govern how one application can talk to another. DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 6

For a long time.. Humans were the only users DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 7

For a long time.. Humans were the only users Software displays results in User Interface (UI) User asks for data or takes action by interacting with UI DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 8

But what about when the user is another software system. Software returns results via API My Software System Software asks for data or takes action by interacting with API Your Software System DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 9

An API is like an electrical outlet. What would it be like to power an hair dryer without an outlet? Open wall Strip wires Splice wires together Understand all the wires in the wall The outlet is a service that conforms to specifications. Sockets deliver 120 volts of alternating current (AC) operating at 60Hz Sets expectation on behalf of consuming devices and provider. DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 10

An API is like An API (Application Programming Interface) is best thought of as a contract provided by one piece of computer software to another. DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 11

APIs help developers create apps that benefit the end user. Google Maps returns map data via API Users sees list of restaurants close to them Yelp asks for Map Data DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 12

APIs are an engine of innovation -Programmable Web DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 13

APIs aren t scary you already use them

Command Line Interface (CLI) Designed for Humans so more a UI than API but... Network Management Systems Expect Scripts Paramiko/Netmiko NAPALM #!/usr/bin/expect -f send "conf t\n" expect "(config)#" send hostname my_switch\n" expect "(config)#" send "ntp server 10.10.10.101\n" expect "(config)#" send "ip domain-name domain.intra\n" expect "(config)#" send "end\n" expect "#" send "write mem\n" expect "#" DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 15

Simple Network Management Protocol (SNMP) designed as a programmatic interface between management applications and devices * Widely used for monitoring Limited use for configuration Network Management Systems primary consumer * https://tools.ietf.org/html/rfc3535 DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 16

Other APIs out there

Simple Object Access Protocol (SOAP) Mature standard designed by Microsoft Used to build Web Services (software available over the internet) Typically uses HTTP, and dependent on XML Sometimes considered complex and rigid DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 18

Representational State Transfer (REST) API framework intended to build simpler web services than SOAP Another use for the HTTP protocol Popular due to performance, scale, simplicity, and reliability Technically an API framework * More detailed coverage in later lessons DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 19

XML-RPC and JSON-RPC Simple frameworks for communicating over HTTP RPC = Remote Procedure Call When one system requests another system to execute code Offer XML and JSON data formats respectively HTTP POST REQUEST BODY: [ { "jsonrpc": "2.0", "method": "cli", "params": { "cmd": "show version", "version": 1 }, "id": 1 } ] DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 20

NETCONF (NETwork CONFiguration) Protocol Designed as replacement for SNMP Standardized in 2006 / Updated 2011 Leverages SSH and XML Defines transport and communication Titled coupled to YANG for data * More detailed coverage in later lessons DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 21

RESTCONF Protocol Provide REST API like interface to network Standardized in 2017 Supports XML and JSON Defines transport and communication Titled coupled to YANG for data * More detailed coverage in later lessons DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 22

What is REST?

Just Another Use for the HTTP Protocol Representational state transfer (REST) API framework built on HTTP APIs often referred to as web services Popular due to performance, scale, simplicity, and reliability DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 24

Requests and Response, the REST API Flow DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 26

Requests and Response, the REST API Flow DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 27

Requests and Response, the REST API Flow DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 28

A Look Under the Hood at REST

The URI: What are you Requesting? http://maps.googleapis.com/maps/api/geocode/json?address=sanjose Server or Host Resource Parameters http:// or https:// Define whether secure or open http Server or Host Resolves to the IP and port to connect to Resource The location of the data or object of interest on the server Parameters Details to scope, filter, or clarify a request. Often optional. DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 30

HTTP Methods: What to do? HTTP Verb Typical Purpose (CRUD) Description POST GET PUT PATCH DELETE Create Read Update Update Delete Used to create a new object, or resource. Example: Add new book to library Retrieve resource details from the system. Example: Get list of books from the library Typically used to replace or update a resource. Can be used to modify or create. Example: Update the borrower details for a book Used to modify some details about a resource. Example: Change the author of a book Remove a resource from the system. Example: Delete a book from the library. DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 31

Response Status Codes: Did it work? Status Code Status Message Meaning 200 OK All looks good 404 Not Found Resource not found DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 32

Response Status Codes: Did it work? Status Code Status Message Meaning 200 OK All looks good 201 Created New resource created 400 Bad Request Request was invalid 401 Unauthorized Authentication missing or incorrect 403 Forbidden Request was understood, but not allowed 404 Not Found Resource not found 500 Internal Server Error Something wrong with the server 503 Service Unavailable Server is unable to complete request DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 33

Headers: Details and meta-data Header Example Value Purpose Content-Type application/json Specify the format of the data in the body Accept application/json Specify the requested format for returned data Authorization Basic dmfncmfuddp2ywdyyw50 Provide credentials to authorize a request Date Tue, 25 Jul 2017 19:26:00 GMT Date and time of the message Used to pass information between client and server Included in both REQUEST and RESPONSE Some APIs will use custom headers for authentication or other purpose DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 34

Data: Sending and Receiving Contained in the body POST, PUT, PATCH requests typically include data GET responses will include data Format typically JSON or XML Check Content-Type header { 'title': 'Hamlet', 'author': 'Shakespeare' } DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 35

HTTP Authentication and Security None: the Web API resource is public, anybody can place call. Basic HTTP: a username and password are passed to the server in an encoded string. Authorization: Basic ENCODEDSTRING Token: a secret generally retrieved from the Web API developer portal. Keyword (ie token) is API dependent Authorization: Token aikasf8adf9asd9akasdf0asd OAuth: Standard framework for a flow to retrieve an access token from an Identity Provider. Authorization: Bearer 8a9af9adadf0asdf0adfa0af Authorization can be short-lived and require refreshing of tokens DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 36

Some REST Examples

The Internet Chuck Norris Database DevNet$ curl https://api.icndb.com/jokes/random { "type": "success", "value": { "id": 201, "joke": "Chuck Norris was what Willis was talkin' about.", "categories": [] } } DevNet$ curl https://api.icndb.com/jokes/random?limitto=nerdy { "type": "success", "value": { "id": 537, "joke": "Each hair in Chuck Norris's beard contributes to make the world's largest DDOS.", "categories": [ "nerdy" ] } http://www.icndb.com/api/ } No authentication needed Well constructed API with many options DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 38

Network Programmability with RESTCONF The Request DevNet$ curl -vk \ -u root:d_vay\!_10\& \ -H 'accept: application/yang-data+json' \ https://ios-xe-mgmt.cisco.com:9443/restconf/data/ietf-interfaces:interfaces/interface=gigabitethernet2 > GET /restconf/data/ietf-interfaces:interfaces/interface=gigabitethernet2 HTTP/1.1 > Host: 10.10.20.21 > User-Agent: curl/7.51.0 > accept: application/yang-data+json > authorization: Basic dmfncmfuddp2ywdyyw50 > -u provides user:password for Basic Authentication -H to set headers Lines beginning with > indicate Request elements Lines beginning with < indicate Response elements (next slide) DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 39

Network Programmability with RESTCONF The Response - Headers < HTTP/1.1 200 OK < Server: nginx < Date: Thu, 27 Jul 2017 00:01:52 GMT < Content-Type: application/yang-data+json < Transfer-Encoding: chunked < Connection: close < Last-Modified: Tue, 25 Jul 2017 19:15:57 GMT < Cache-Control: private, no-cache, mustrevalidate, proxy-revalidate < Etag: 1501-10157-179272 < Pragma: no-cache < The Response - Data { "ietf-interfaces:interface": { "name": "GigabitEthernet2", "description": "Wide Area Network", "type": "iana-if-type:ethernetcsmacd", "enabled": true, "ietf-ip:ipv4": { "address": [ { "ip": "172.16.0.2", "netmask": "255.255.255.0" } ] }, "ietf-ip:ipv6": { } } } DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 40

Demo

REST API Tools

Many Options for Working with REST APIs curl Linux command line application Postman Chrome browser plugin and application Requests Python library for scripting Swagger Dynamic API Documentation Browser Developer Tools View traffic and details within browser DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 43

Summing up

Review REST APIs are built on the HTTP Protocol Requests and Responses How are URIs constructed Methods, Status Codes, and Headers used with REST APIs Authentication options for HTTP Looked at some example API calls DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 45

Cisco Spark How Questions? Use Cisco Spark to communicate with the speaker after the session 1. Find this session in the Cisco Live Mobile App 2. Click Join the Discussion 3. Install Spark or go directly to the space 4. Enter messages/questions in the space cs.co/ciscolivebot#devnet-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public

Please complete your Online Session Evaluations after each session Complete 4 Session Evaluations & the Overall Conference Evaluation (available from Thursday) to receive your Cisco Live T-shirt All surveys can be completed via the Cisco Live Mobile App or the Communication Stations Complete Your Online Session Evaluation Don t forget: Cisco Live sessions will be available for viewing on-demand after the event at www.ciscolive.com/global/on-demand-library/. 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public

Continue Your Education DevNet: https://developer.cisco.com DevNet Learning Labs: https://learninglabs.cisco.com DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 48

Got more questions? Come find me! mdenaol@cisco.com @denapom11 http://github.com/denapom11 @CiscoDevNet facebook.com/ciscodevnet/ http://github.com/ciscodevnet DEVNET-3607 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public 49

Thank you