Upload
cisco-devnet
View
237
Download
4
Embed Size (px)
Citation preview
Coding 102REST API Basics using SparkDavid STAUDT, Developer Evangelist, [email protected]
Stève SFARTZ, API Evangelist, [email protected] DEVNET-2002
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
• REST API Basics • A tour of Cisco Spark API• Interactive Documentation Hands-on • Postman Hands-on• Javascript examples
• Pre-requisites• You know how to forge API requests with Postman (or a similar REST client)• If not, attend DEVNET-1001: Coding 101- Introduction to REST APIs
Agenda
DEVNET-2002 2
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
REST API BasicsCoding 101 Prerequisites – DEVNET1001
DEVNET-2002 3
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public 4
What is so great about REST? same concept, many Cisco APIs
Easy to BuildWeb appsMobile appsM2M, Bots…
REST API
DEVNET-2002
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public 5
Terminology of a REST API query
GET /../repos?page=1 HTTP/1.1 accept: application/json
HTTP 200 OK
browser api.github.com:443
method path protocol
status code
https://api.github.com/users/CiscoDevNet/repos?page=1&per_page=2
headers
URL:
response body
HTTP request
HTTP response
api endpoint
JSON payload
parameters
DEVNET-2002
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public 6
http://getpostman.com• Want to code along? Install POSTMAN now
• Free tool to forge API requests, examine responses
DEVNET-2002
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public 7
method
url
requestheaders
status code
response headers
content-type
responsebody
query parameters
DEVNET-2002
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public 8
JSON syntax• square brackets for lists
• curly braces for objects
• name/value pairs for properties, separated by commas
• pick an online editor
• http://codebeautify.org/jsonviewer http://www.jsoneditoronline.org
DEVNET-2002
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
Cisco Spark for DevelopersA tour of Cisco Spark APIs
DEVNET-2002 9
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public 10
Cisco Spark
Secure & Open
Complete & Simple
Spark for DevelopersUser Integrations, APIs/SDKs, etc.
Spark Hybrid ServicesCloud + Prem
Partner ServicesInterconnect
Message Meeting Call
DEVNET-2002
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public 11
‘Your App’ now with
Cisco Collab!
Spark APIs Extend Cisco Collaboration Cloud
GET
POST
DELETE
PUT /Rooms
/Memberships
/Messages
/Teams
/People
DEVNET-2002 11DEVNET-2002
/Webhooks
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public 12
Cisco Spark API v1 (July 2016)/People /Rooms /Membership /Messages /Teams /Webhooks
List People List Rooms List Memberships List Messages List Teams List Webhooks
Create a Room Create a Membership Create a Message Create a Team Create a Webhook
Get Person Details Get Room details Get Membership details Get Message details Get Team details Get Webhook details
Update a Room Update a Membership Update a Team Update a Webhook
Delete a Room Delete a Membership Delete a Message Delete a Team Delete a Webhook
GET
POST
DELETE
PUT
DELETE DELETE DELETE
PUT PUT
POST POST POST
GET GET GET
GET GET
GET
GET GETGET
DEVNET-2002
DELETE
PUT
POST
GET
GET
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
Hands onlist your Spark Rooms with the Interactive Documentation
DEVNET-2002 13
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
Developer Portal Interactive API documentation
Client SDKs
developer.ciscospark.com
24/7 Dev Support
DEVNET-2002 14
15
16
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
Hands-on Instructions• Go to « List Rooms » documentation on the Developer Portal
https://developer.ciscospark.com/resource-rooms.html
• Login: and Turn « Test Mode » on:
• Run the query:
17
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
Hands onadd a Message to a Roomwith Postman
DEVNET-2002 18
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
Demo : list Rooms from Postman
19DEVNET-2002
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public 20DEVNET-2002
Hands onImport the Postman collection
bit.ly/DEVNET2002
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public 21
Hands on
• Get your Cisco Spark Token from developer.ciscospark.com
• Fill in the Authentication Header• Authorization : Bearer YOUR_SPARK_TOKEN
• List some Rooms you are a member of
Add a Message to a Room with Postman
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
Hands on
• Pick a Room identifier « RoomId »
Add a Message to a Room with Postman
22DEVNET-2002
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public 23
Hands on
• Forge a POST request to create a message • API documentation : https://developer.ciscospark.com/endpoint-messages-post.html
Add a Message to a Room with Postman
DEVNET-2002
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public 24
POSTED !!!• 200 OK
• Check Message Id & attachments
DEVNET-2002
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
Cisco Spark for DevelopersSpark API calls in Javascript
DEVNET-2002 25
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public 26
How to request from Javascript
• A benefit of REST is that you can invoke Spark from any language
• Hand code with your favorite HTTP client library
• Or generate code from Postman
• OAuth 2 to inject user API token
Do It Yourself … with Postman code assistants
DEVNET-2002
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public 27
How to request from NodeJS
1. Generate a nodejs skeleton from Postman, 2. Run from the command line
Do It Yourself … with Postman code assistants
DEVNET-2002
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public 28
How to request from NodeJS
• Official « ciscospark » SDK
• Community SDKs• nmarus Sparky, • drkchiloll/csco-spark• …
… or choose with a ready-to-use SDK
https://github.com/nmarus/sparky https://www.npmjs.com/package/ciscospark
DEVNET-2002
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public 29
Continue Your Education in the DevNet Zone• Take a Spark Learning Lab
1. Create Rooms, Adding Participants and Posting Messages 2. Learn to create a Webhook that will subscribe to new messages in a room3. Register a new Spark app, and authenticate from a browser based apphttps://developer.ciscospark.com/samples-tutorials.html
• Attend other Spark API sessions or take an instructor-driven Workshop• DEVNET-2020: [Workshop] Working with Spark APIs • DEVNET-2021: Spark API Authentication - Bots and Oauth• DEVNET-2025: [Workshop] Build a Multi-Function iPaaS Application Using Python• DEVNET-3002: [Workshop] Tour the DevNet Quiz App (Spark & Tropo Integration)• BRKDEV-2004: Cloud Integration Platform Use-Cases and Coding Walk-Through
DEVNET-2002
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public 30
Continue Your Education in the DevNet Zone• Take the DevNet « Coding Track »
• DEVNET-1001: Coding 101, Introduction to REST APIs • DEVNET-1060: Intro to API Authentication Types (Oauth, token HTTP Basic)• DEVNET-1080: Introduction to Git• DEVNET-2002: Coding 102, REST API Basics using Spark• DEVNET-2003: Coding 102, REST API Basics using APIC-EM• DEVNET-2006: Coding 103, Deep Dive on JSON & more Python
• Meet the Experts at the Demo Pods
• Become a DevNet Community member www.developer.cisco.com
DEVNET-2002
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public 31
Continue Your Education• Demos in the Cisco campus
• Walk-in Self-Paced Labs
• Lunch & Learn
• Meet the Engineer 1:1 meetings
• Related sessions
DEVNET-2002
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
Complete Your Online Session Evaluation
Don’t forget: Cisco Live sessions will be available for viewing on-demand after the event at CiscoLive.com/Online
• Give us your feedback to be entered into a Daily Survey Drawing. A daily winner will receive a $750 Amazon gift card.
• Complete your session surveys through the Cisco Live mobile app or from the Session Catalog on CiscoLive.com/us.
32DEVNET-2002
Thank you
© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Public
@CiscoSparkDev
@CiscoDevNet
DEVNET-2002 33