Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Â
Nom Nom: Consuming REST APIs
1. MadisonPHP Conference October 1st, 2016
Consuming Rest APIs
Follow me on Twitter and/or tweet at me. @tessamero
By Tessa Mero
Nom Nom: Consuming
Rest APIs
3. ⢠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
4. ⢠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?
5. 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
7. API Growth from 2000 to 2016
0
5000
10000
15000
20000
25000
30000
35000
2000 2005 2007 2009 2011 2013 2015 2016
API's
API's
Source: 2016 data from nordicapis.com. 2005-2015 data from
rubenverborgh.github.io and 2000-2004 data from blog.cutter.com
9. Ready for a lot of
examples?
Iâll make it sound easy ď
10. âItâs a way for two pieces of software to
talk to each otherâ
Application Programming Interface
11. The API is the User
Interface for software
systems
12. APIs are sets of
requirements that govern
how one application can talk
to another.
13. 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.
14. 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
16. 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
17. Three Types of Web Services for Providing APIs
Remote 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
22. ⢠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
34. 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
39. You created a room, now
how do you post a message
to it through an API request?
40. 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 Message
3. Test the API request.
4. Make Magic Happen.
Create Message API Request
54. 4. Write some JavaScript
call("+14258791911", {
network:"SMSâ
});
say("Don't forget your meeting at 2 p.m. on
Wednesday!");
55. 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&t
oken=6c7a56555271337716e76596b6266456254
566e4e625058657133776456d6d7a504f4b4b4133
7a71624c
58. ⢠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
Hello Everyone! My name is Tessa Mero.
I want to give a huge Thank You to the conference organizers for putting together this amazing event and allowing me to have the opportunity to speak to you.
I also want to thank the Brazilian JavaScript community for being so welcoming here!
You can Tweet at me during the session @tessamero
The act of Consuming a Rest API means to eat it all up, so in context it means to eat it, swallow it up, and digest it leaving any others in the pile exposed.
So it basically just means to use an API.
Here is an overview of what Iâll be going over.
I am a Developer Advocate for Cisco DevNet. DevNet is the Developer Department for Cisco. Iâve recently started this job earlier this year and I love it. Developer Advocates reach out to developers and bring awareness to our products, such as our APIs. Thatâs why Iâm always talking about APIs ď
My previous job was teaching Web Application Development at a College for many years, including JavaScript and PHP courses. I also have a degree in web development as well. Iâm always a teacher at heart, so Iâve always made myself available to mentor developers to help them become successful.
I am obsessed with Free & Open Source Communities. Iâve been speaking at Joomla and PHP conferences for many years. I also run several developer meetups and a conference in Seattle, which is in the US.
I have 2 children. I have a son named Jayden who is 7 years old. I also have a daughter named Emma who is 5 years old. They drive me crazy. Iâm kidding, they are the most wonderful kids ever and they are my motivation to do everything that I do today.
What is DevNet? DevNet is a developer program created 2 years ago. Cisco decided it was time to turn the company from a network company to a software and services company.
Our purpose is to create APIs and software to help our partners and customers have better products.
We go to programming events and all types of conferences to help promote that we are not a network company.
Iâm not here to sell anything as we focus on selling internally and to partners and customers.
We love giving out swag at events. I didnât feel like bringing an extra suitcase today, so no swag. ď
We absolutely love getting attention on @CiscoDevNet. A wonderful colleague of mine is amazing at her social media work on all of our DevNet accounts. She gets excited when you tweet at her. Even more excited if you ask for stickers!
Why are APIâs so important? Most companies today have several different softwareâs they need to use, including sales, accounting, CRM, a project management system, etc.
To have the software all work together is becoming a more important thing for both synergy and financial reasons and is making tasks much easier for work processes.
They can also create their own tool to enhance their software, making their customers happier.
As you can see that the amount of APIâs out there started with 1 API in 2000 (Ebay) and has exponentially increased over time.
In 2016, there has been more than 50 million API requests made and 30,000 available APIâs out there.
From 2015 to 2016, it has doubled in growth from 15,000 to 30,000 and only exponentially increasing.
Okay, so what is an API?
Ready for a lot of examples?
Iâll make it sound easy ď
An API stands for Application Programming Interface
Itâs a way for two pieces of software to talk to each other.
Which brings me to saying that the API is the User Interface for software systems.
APIs are sets of requirements that govern how one application can talk to another.
An API is best thought of as a contract provided by one piece of computer software to another.
I will use Yelp as an example.
Yelp displays nearby restaurants using the Google Map API by âexposingâ some of the programâs internal functions to the outside world in a limited fashion. This makes it possible for applications to share data without requiring developers to share all of their code.
APIs simplify all of that by limiting outside program access to a specific set of features by allowing them to request data.
Think of it as doors or windows, or even levers.
APIs make it possible to use a mix and match of APIs, such as Google API, Facebook API, or Twitter API, and make an entire new app and service.
The widespread of APIâs for major services is what made the modern web experience possible today.
APIs are often referred to as âan engine of innovationâ
Because of API, there are so many cool applications out there that wouldnât exist no.
REST API versus Web API, if youâve heard the two terms before.
REST describes a way of interacting with a HTTP server. Not what the server should return in response.
HTTP implements methods (which is also known as verbs) other than GET or POST. It also implements HEAD, which is without the response body, and PUT and DELETE, which Iâll go over a little later.
A REST interface simply makes use of these additional verbs to convey the meaning of the request to the server.
Web services are set of platform independent exposed APIs(functions) which can be used used from remote server over the Internet. So there are 3 different types of web services for providing APIs.
The first one is called Remote Procedure Call (RPC). It uses a single URI and gives the responses in a structured format, but lacks the amount of responses it can give out, especially compared to REST.
Simple Object Access Protocol (SOAP) is more powerful and preferred by software vendors like Microsoft,.NET, Java Enterprise Edition, and that sort of thing. SOAP is the most used tool and the preferred tool between 2001-2007.
Representational State Transfer (REST) is what Iâll be going over since it is the most popular web service to use. Each unique URL is a representational of some object, hence where the acronym REST came from. The results are human readable, and itâs also much light weight compared to other web services.
You can find more in depth information about all 3 on tiny.cc/webservices.
Next we will go over web pages, requests, responses, and REST APIs
When you view a web page, it sends a request to the web server, and sends a response back.
So you are making a request and getting a response.
When you send your HTTP request, you are sending a GET request.
You get your response as an HTTP response code, where 200 means good, and everything came back okay.
This is exactly what is happening between your app and their app between an API
Here are some common HTTP status codes that you will get when you request a web page.
When you make a request with an API, you also get a response back with a status code.
Usually you will be hoping for 200 OK.
Using Cisco Spark API as a use case, of course.
To understand a specific API, you must know what the application actually does. Cisco Spark is a collaboration tool, similar to Slack or Glip, that allows you to chat, have meetings, and video chat.
Spark is designed to be a very light weight option so developers can customize it to their company needs.
We are releasing an app marketplace of free plugins so people can download Spark and install plugins that they will actually use, rather than have a tool that has more features than you actually need.
So how do you interact with this particular API? Well, there are methods you can make to request data.
When you are getting data using an API, you make your request.
In this flow chart, you see that your app is asking to make a list of Spark rooms, then the Spark server prepares the data and sends the list of spark rooms back.
And you can have it parsed in any parsing format you want, such as JSON or XML, which are the 2 most popular. Donât ask which is better to use, since they both have their pros and cons. It really depends on what you are doing in your application.
So your Application would be the API consumer, the request is GET /rooms and the Cisco Spark API is the API Provider.
Then the return result is a HTTP 200 OK.
This is a list of different HTTP routing methods you can use to make a request.
GET --- Can get a list of items, or get an individual item id
POST --- Creates an item
PUT --- Updates an item
DELETE â Deleteâs an item
So how do we test these API requests to check if it works first?
When you are working with APIs, you will commonly have API problems that you need to solve. There are a kazillion tools out there. Thereâs a website that lists out 60 tools you can use to solve your problems, (note: not mental problems), and you can find it at tiny.cc/60tools
Webhook Debugging (RequestBin formerly requestbin.orgâŚ) â Inspect requests
Webhook Utilities (TorpioâŚ) â Webhook Delivery Platform. BAM!
Local Tunneling (ngrokâŚ) â Tunnel to Localhost, weeeeeeeeeeeee
API Monitoring (RunscopeâŚ) â API monitoring/testing, chained requests/oauth sup.
Response Mocking (mocky.io...) â Mock API response, duh!
JSON Utilities (JSONFormat...) â Make URL very pretty!
OAUTH Utilities (oauth.io...) â Integrate Oauth EZ Peezy!
API Directories (APIS.io, ProgrammableWeb...) â Directory of... Ummmm...
API Testing (Runscope Radar...) â Test in cloud (not real cloud). Email/Webhook notification for when youâre a failure and suck at APIs
Load Testing (loader.io...) â Test with thousands of concurrent connections. Because scaling is important.
GUI HTTP Clients (POSTMAN...) â An interface for creating and testing requests and what we are going to go over next!
This is where POSTMAN comes in handy.
Iâll show you how to work with REST API Calls. First, install the Chrome plugin Postman, or you can install it as an individual app on the Mac.
Itâs a free tool to forge API Requests and examine responses.
For Mozilla or Safari, you can install a plugin called RESTClient
Letâs understand how Postman is working with the Github API here.
Letâs create an HTTP request to github.com
Leave the GET method as is.
Enter the URL of the resource.
Press the Send button
Postman issues the HTTP call on your behalf, and shows the response by the Github API:
Here it shows the response is 200 OK towards the bottom right.
The HTML page contents are placed in the Body
Now What? How do you figure out how to use an API?
A great API will have great documentation.
If people cannot figure out how to use your API, then you will not have as many users as you were hoping for. The most popular APIâs out there have very well written documentation.
You could have the best API in the world, but if developers cannot figure out how to use it, they will find something else.
For Reviewing the DocumentationâŚ
To start learning a new API, you first find the documentation page.
You find the API reference and figure out what you want to do.
Then you test your API request via Postman because it is fun!
I want to first create a room in Spark and test it through POSTMAN.
Hereâs a closer look at the API reference for Rooms.
You can List Rooms,
Create a Room,
Get Room Details,
Update a Room,
and Delete a Room.
In this example, I created a title of a room called âPHPCruise Roomâ.
I knew to use title because of the API documentation.
After clicking on Submit, I opened up my Cisco Spark.
There is now a new room called âPHPCruise Roomâ that I created in POSTMAN from an API Call.
You created a room, now how do you post a message to it through an API Request?
To create a message API request you will need to take note of the key generated for the room you created which is your roomID.
Refer to the documentation for creating a message.
Test the API Request, which makes magic happen.
So what do we do next? Oh right, we go back to the documentation to find out what HTTP request to make to create a message.
Looks like it is the 2nd one here, so we will use the method POST.
But what about request parameters?
Oh right, that documentation stuff again.
This is the list of parameters you can use for the messages
Letâs use roomId and text as an easy example to demonstrate.
Add the JSON data of the roomId and text to the body.
The roomId is what you received when creating a room.
The text is the message you want.
You click Send and it will now post a message to your room. Go ahead and try it when you get home. Itâs very easy!
There is one important thing you need to do when you receive a 200 OK HTTP Status. Please take note of this.
You do a dance!
Alright I get it. Now show me something else thatâs cool!
How about⌠applications interacting with a cell phone?
Tropo is a voice/SMS API that compares to Twilio. It was acquired by Cisco over a year ago.
You can find the website at tropo.com.
You can build really cool applications that interact with your phone, or use the Tropo API as an integration to your software.
This is my favorite one to show people because developers seem very excited that this could help improve their software.
Iâll quickly go over how you can create your first application and use the Tropo API.
It can literally take you less than 5 minutes even without developer experience.
First, of course, youâd have to create an account on tropo.com
First you give your App a name. In this one I give it âTessaâs Texting Serviceâ.
Leave it at default for Development as the App Status, so it is free to use.
Edit your Script and create a name, such as textService.js.
You can select a Country, such as Brazil, and select which Region in the country and click Add.
Here would be the JavaScript that you would write to send a text message.
Replace my phone number with yours of course.
To allow SMS to work on your application, you would need to put in a support ticket to get your account activated for it.
I could also do it for you on my end and activate your account.
You can launch your app by using a token URL into the browser to make a request and fire off your application.
Simply add a question mark after the method call and before putting in the query parameters.
Each query parameter is separated by an & sign.
Magic? I know right? The phone number above is my apps phone number that sent my phone a text message.
You can do it too! Itâs that easy. And you may experience this with most APIâs with great documentation!
Here are the most used functions with the Tropo API.
You can make calls, answer, log information about a call, say something, ask a question, and record.
You can even do speech to text.
Easy? I knowâŚ
The Spark Innovation Fund is a budget that was given to my department where we pay developers to create a startup that we will fund.
The startup that you build stays under your name or your business name.
We want to market our APIs and drive our developer ecosystem. This will only benefit you.
Our budget we were given is 150 Million USD Dollars.
You can learn more about it at developer.ciscospark.com/fund.
Also, donât forget to tweet at me @tessamero
So, I hope you you feel highly consumed and full from this API talk.
If you are new to APIs and need help getting started, or simply want to try out our Cisco APIs, please do not hesitate to contact me.
THANK YOU!