+ All Categories
Home > Technology > Nom Nom: Consuming REST APIs

Nom Nom: Consuming REST APIs

Date post: 07-Jan-2017
Category:
Upload: tessa-mero
View: 166 times
Download: 0 times
Share this document with a friend
64
ZendCon Conference October 2016 Consuming Rest APIs Follow me on Twitter and/or tweet at me. @tessamero By Tessa Mero Nom Nom: Consuming Rest APIs
Transcript
Page 1: Nom Nom: Consuming REST APIs

ZendCon Conference October 2016Consuming Rest APIs

Follow me on Twitter and/or tweet at me. @tessamero

By Tessa Mero

Nom Nom: Consuming Rest APIs

Page 2: Nom Nom: Consuming REST APIs

2© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

CONSUME THE REST APIS!

Page 3: Nom Nom: Consuming REST APIs

3© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

• Who Am I?• WHAT ARE APIs• Requests and Responses• Intro to APIs• Playing with Spark API• Playing with Tropo API• Taking Knowledge Home With You

Overview

@tessamero

Page 4: Nom Nom: Consuming REST APIs

4© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

• Developer Advocate• Teacher/Mentor• Previously Web Developer• <3 Free & Open Source• Community Leader for

Joomla and PHP

• Mother of 2• I love APIs• Addicted to Twitter

(@tessamero)

Who Am I?

Page 5: Nom Nom: Consuming REST APIs

5© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Cisco DevNet? Why Am I Here?

• What is DevNet?• What is the Purpose?• Why do we go to programming

conferences?

• Not Selling Anything• We Like Giving Out Swag• We Like attention

@ciscodevnet

Page 6: Nom Nom: Consuming REST APIs

6© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Why are API’s so important?

Page 7: Nom Nom: Consuming REST APIs

7© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

API Growth from 2000 to 2016

2000 2005 2007 2009 2011 2013 2015 20160

5000

10000

15000

20000

25000

30000

35000API's

API's

Source: 2016 data from nordicapis.com. 2005-2015 data from rubenverborgh.github.io and 2000-2004 data from blog.cutter.com

Page 8: Nom Nom: Consuming REST APIs

8© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Okay, What is an API?

Page 9: Nom Nom: Consuming REST APIs

9© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Ready for a lot of examples? I’ll make it sound easy

Page 10: Nom Nom: Consuming REST APIs

10© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

“It’s a way for two pieces of software to talk to each other”

Application Programming Interface

Page 11: Nom Nom: Consuming REST APIs

11© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

The API is the User Interface for software systems

Page 12: Nom Nom: Consuming REST APIs

12© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

APIs are sets of requirements that govern how one application can talk to another.

Page 13: Nom Nom: Consuming REST APIs

13© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

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.

Page 14: Nom Nom: Consuming REST APIs

14© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

APIs help developers create apps that benefit the end user.

Yelp asks for Map Data

Google Maps returns map data

via API

Users sees list of

restaurants close to

them

Page 15: Nom Nom: Consuming REST APIs

15© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

15Presentation ID

-- Programmable Web

APIs are often referred to as “an engine of innovation.”

Page 16: Nom Nom: Consuming REST APIs

16© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

REST API versus Web API

• No difference at all. It doesn’t give a different output.

• HTTP implements methods.

• A REST interface simply sends request to server

Page 17: Nom Nom: Consuming REST APIs

17© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Three Types of Web Services for Providing APIsRemote Procedure Call (RPC) or XML-RPC

• Single URI

• Response is in a Structured Format

• Lacks Responses

Simple Object Access Protocol (SOAP)

• More powerful, preferred by software vendors (MSFT,.NET,Java Entprse Edition, etc)

• SOAP most used tool 2001-2007

Representational State Transfer (REST)

• Most popular web service

• Each unique URL is a representational of some object

• Easy to read results

• Light Weight – Not much XML markup

http://tiny.cc/webservices

Page 18: Nom Nom: Consuming REST APIs

18© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Requests and Responses

Page 19: Nom Nom: Consuming REST APIs

19© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

19

View a Web Page

Presentation ID

Page 20: Nom Nom: Consuming REST APIs

20© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

20

View a Web Page

Presentation ID

Request GET /index.htm HTTP/1.1

ResponseHTTP 200 OK

<html>

Page 21: Nom Nom: Consuming REST APIs

21© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

REST APIs use Request and Response too

Page 22: Nom Nom: Consuming REST APIs

22© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

• 200 OK• 301 Moved Permanently• 302 Found• 307 Temporary Redirect• 400 Bad Request• 403 Forbidden

Common HTTP Status Codes

• 404 Not Found• 500 Internal Server

Error• 550 Permission Denied

Page 23: Nom Nom: Consuming REST APIs

23© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Using Cisco Spark API as a Use Case. Of course =P

Page 24: Nom Nom: Consuming REST APIs

24© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

So how do you interact with this API?

Page 25: Nom Nom: Consuming REST APIs

25© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

25

Get Data using an API

Presentation ID

Page 26: Nom Nom: Consuming REST APIs

26© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

26

Get Data using an API

Presentation ID

Request GET /rooms

ResponseHTTP 200 OK

{json data}

API Consumer API Provider

Page 27: Nom Nom: Consuming REST APIs

27© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Page 28: Nom Nom: Consuming REST APIs

28© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Tools to Debug/Test http://tiny.cc/60tools

• Webhook Debugging (RequestBin formerly requestbin.org…)• Webhook Utilities (Torpio…)• Local Tunneling (ngrok...)• API Monitoring (Runscope...)• Response Mocking (mocky.io...) • JSON Utilities (JSONFormat...)• OAUTH Utilities (oauth.io...)• API Directories (APIS.io, ProgrammableWeb...)• API Testing (Runscope Radar...)• Load Testing (loader.io...)• GUI HTTP Clients (POSTMAN...)

Page 29: Nom Nom: Consuming REST APIs

29© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Postman!!!! =)

Page 30: Nom Nom: Consuming REST APIs

30© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Test Your REST API Requests = FUN

Page 31: Nom Nom: Consuming REST APIs

31© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

31

method

url

requestheaders

status code

response headers

content-type

responsebody

query parameters

Page 32: Nom Nom: Consuming REST APIs

32© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Now What? How Do You Figure Out How To Use an API?

Page 33: Nom Nom: Consuming REST APIs

33© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

One Word: Documentation

Page 34: Nom Nom: Consuming REST APIs

34© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

1. First, find the documentation page. If you cannot find it, then that’s a problem.

2. Find the API Reference.

3. Figure out what you want to do.

4. Test your API request via Postman because it’s fun :P

Reviewing the Documentation

Page 35: Nom Nom: Consuming REST APIs

35© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

The API Reference!

Page 36: Nom Nom: Consuming REST APIs

36© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

API Reference: Rooms

Page 37: Nom Nom: Consuming REST APIs

37© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Room Created!

Page 38: Nom Nom: Consuming REST APIs

38© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

PHPCruise Room Created!

Whoa!!!!

Page 39: Nom Nom: Consuming REST APIs

39© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

You created a room, now how do you post a message to it through an API request?

Page 40: Nom Nom: Consuming REST APIs

40© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

1. Take Note of Key generated when you created a room, so now your room has an ID.

2. Refer to documentation for Creating a Message3. Test the API request.

4. Make Magic Happen.

Create Message API Request

Page 41: Nom Nom: Consuming REST APIs

41© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Oh yeah, the documentation….

Page 42: Nom Nom: Consuming REST APIs

42© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

But what about request parameters?

Page 43: Nom Nom: Consuming REST APIs

43© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Oh yeah, the documentation!

Page 44: Nom Nom: Consuming REST APIs

44© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Create your request parameters in the body.Feelin’ 200 OK

Oh my gosh I can’t see it what does it say?

Page 45: Nom Nom: Consuming REST APIs

45© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

One important thing to do when you receive a 200 OK HTTP Status:(Please take note of this)

Page 46: Nom Nom: Consuming REST APIs

46© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Page 47: Nom Nom: Consuming REST APIs

47© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Alright I get it. Now show me something else that’s cool!

Page 48: Nom Nom: Consuming REST APIs

48© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

How About… Applications Interacting With a Cell Phone?!

Page 49: Nom Nom: Consuming REST APIs

49© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Introducing the Tropo API! IT’S SO MUCH FUNZ

Page 50: Nom Nom: Consuming REST APIs

50© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

What Can You Do With Tropo?

Page 51: Nom Nom: Consuming REST APIs

51© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Create an Application:

Register (anyone can, free)

Click on “My Apps”

Click on “Create New App”

Page 52: Nom Nom: Consuming REST APIs

52© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

1. Create Name2. Click on “Edit Script” and give it a name. This is: textService.js

Page 53: Nom Nom: Consuming REST APIs

53© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

3. Add a Phone Number (Free for Dev)

Page 54: Nom Nom: Consuming REST APIs

54© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

4. Write some JavaScript

call("+14258791911", { network:"SMS”

});

say("Don't forget your meeting at 2 p.m. on Wednesday!");

Page 55: Nom Nom: Consuming REST APIs

55© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

5. LAUNCH IT!

You can put your token URL in the browser to make a request and fire off your app

https://api.tropo.com/1.0/sessions?action=create&token=6c7a56555271337716e76596b6266456254566e4e625058657133776456d6d7a504f4b4b41337a71624c

Page 56: Nom Nom: Consuming REST APIs

56© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Magic!

Page 57: Nom Nom: Consuming REST APIs

57© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

You can do it too!

Page 58: Nom Nom: Consuming REST APIs

58© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

• call();• answer();• _log();• say();• ask();• record();

• Makes a call• Answers the call (when called)• Logs the info about the call• Says something• Says something in a question• Records the call (like

voicemail), with certain parameters, you can transcribe caller input too!

Other Functions To Use

Page 59: Nom Nom: Consuming REST APIs

59© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Easy? I know…

Page 60: Nom Nom: Consuming REST APIs

60© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Spark Innovation Fund?

Page 61: Nom Nom: Consuming REST APIs

61© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

$1,000,000 x 150….

Page 62: Nom Nom: Consuming REST APIs

62© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

I like money too, trust me…

https://developer.ciscospark.com/fund/

Also, don’t forget to tweet at me @tessamero

Page 63: Nom Nom: Consuming REST APIs

63© 2016 Cisco and/or its affiliates. All rights reserved. Cisco Confidential

Thank You

Page 64: Nom Nom: Consuming REST APIs

Recommended