SlideShare a Scribd company logo
Using an API
Using an API

   Tools
       HTTPie
       CURL
       Charles – http://www.charlesproxy.com
       Firebug – https://getfirebug.com
Using an API

   HTTPie
       Great for debugging APIs rather than using cURL
       http://www.httpie.org
       Free
       Requires Python
          POST /books HTTP/1.1
          HOST: example.com
          Content-Type: application/hal+json
          Accept-Encoding: identity, deflate, compress, gzip
          Accept: application/hal+json
          User-Agent: HTTPie/0.2.0

          {
               “author”: “Stoyan Stefanov”,
Using an API

   Charles
       http://charlesproxy.com
       Great for debugging AJAX and Flash AMF requests
       Worth the $50 license fee, but (at least on Ubuntu)
        you can use it free, though it shuts down after 30
        minutes.
Using an API

   cURL
       Great to use via PHP, but for command line use
        HTTPie.
   Firebug
       Great for debugging from Firefox.
   Others
       I hear IE has an OK debugging tool like Firebug.
       I have also heard Chrome has a great Firebug'ish
        tool also.
Using an API

   What is an API?
       Application programming interface
                  A specification intended to be used as an
                    interface by software components to
                    communicate with each other. - wikipedia
Using an API

   API types (popular)
       SOAP – Simple Object Access Protocol
       REST – Representational State Transfer
                   (RFC 2616)
       Javascript
       Screen scrape
Using an API

   SOAP basics
       Relies on XML as its message format.
       Uses HTTP, SMTP, TCP, or JMS for transport, but
        usually HTTP.
       Generally uses a WSDL (Web Services Description
        Language) configuration file making it easier to
        build for or connect to the API.
       Cross platform and cross language.
       Very structured – each action is defined (addUser,
        getUsers, getNewUsersSince, etc.)
Using an API

   Javascript basics
       Client side execution
       Communication from client to server
       Usually methods are defined on server side
        (getThis, addThat, etc.)
       Perception of interactivity (desktop feel)
       Can be asynchronous
       Used by Google Maps and others
Using an API

   Screen scrape basics
       Not a true client/server api.
       Relies on regular expression matching of content.
       Usually done over HTTP using cURL.
       Breaks when server content changes.
       Must download all content, so may be slow and
        resource intensive.
Using an API

   REST basics (main focus for this talk)
       Client-Server
       Stateless – each request is complete and self
        contained (struggle with sessions and cookies)
       Cacheable
       Layered – client cannot tell if using end-server,
        allows load balancers, caches, logging, auth.
       Uniform interface – decoupled from architecture
       Methods – GET, POST, PUT, DELETE, HEAD,
        OPTIONS, TRACE, CONNECT
Using an API

   REST safe methods
       No side effects on the server
       GET & HEAD should make no other action than to
        retrieve.
       Allows user agents to represent POST, PUT, and
        DELETE special. (most browsers do not support
        PUT and DELETE out of the box)
Using an API

   Idempotence
       Operations that can be applied multiple times
        without changing the result. (Ex.- N>0 identical
        requests would have the same output)
       GET, HEAD, PUT, and DELETE share this property
       OPTIONS and TRACE are inherently idempotent.
Using an API

   GET
       Safe and idempotent
       No effect on the server


          GET /books/9790482c HTTP/1.1
          Host: example.com
          Accept-Encoding: identity, deflate, compress, gzip
          Accept: application/hal+json
          User-Agent: HTTPie/0.2.0
Using an API

   GET response
       HTTP/1.1 200 OK
       Date: Wed, 08 Aug 2012 09:32:42 GMT
       Server: Apache/2.2.22 (Ubuntu)
       X-Powered-By: PHP/5.3.10-1ubuntu3.2
       ETag: “9790482c-1”
       Last-Modified: Wed, 08 Aug 2012 04:14:30 GMT
       Content-Length: 254
       Content-Type: application/hal+json

       {
           “_links”: {
                  “self”: {
                     “href”: “http://example.com/books/9790482c”
                  }
           },
           “author”: “Luke Welling, Laura Thomson”,
           “id”: “9790482c”,
           “isbn10”: “0672329166”,
Using an API

   POST
       Not safe
       Not idempotent (same post multiple times could
        have different effects on server)
       Used to create resource
       Is often used to also update a resource, though
        PUT is more for updating.
Using an API

   POST example
       POST /books HTTP/1.1
       HOST: example.com
       Content-Type: application/hal+json
       Accept-Encoding: identity, deflate, compress, gzip
       Accept: application/hal+json
       User-Agent: HTTPie/0.2.0

       {
           “author”: “Stoyan Stefanov”,
           “isbn10”: “1449320198”,
           “isbn13”: “9781449320195”,
           “publisher”: “O'Reilly Media”,
           “title”: “Javascript for PHP Developers”,
           “year”: 2012
       }
Using an API

   Created Response
       HTTP/1.1 201 Created
       Date: Sun, 29 Jul 2012 23:26:49 GMT
       Server: Apache/2.2.22 (Ubuntu)
       X-Powered-By: PHP/5.3.10-1ubuntu3.2
       Location: http://example.com/books/decd0562
       Etag: “decd0562-1”
       Last-Modified: Sun, 29 Jul 2012 23:26:49 GMT
       Content-Length: 239
       Content-Type: application/hal+json

       {
           “_links”: {
                  “self”: {
                     “href”: “http://example.com/books/decd0562”
                  }
           },
           “author”: “Stoyan Stefanov”,
           “id”: “decd0562”,
           “isbn10”: “1449320198”,
Using an API

   PUT
       Not safe
       But is idempotent
       Primarily an update action, but can also be used to
        create though POST should be used for that.
Using an API

   Sample PUT

     PUT /books/decd0562 HTTP/1.1
     HOST: example.com
     Content-Type: application/hal+json
     Accept-Encoding: identity, deflate, compress, gzip
     If-Match: “decd0562-1”
     Accept: application/hal+json
     User-Agent: HTTPie/0.2.0

     {
         “_links”: {
                “self”: {
                   “href”: “http://example.com/books/decd0562”
                }
         }
         “author”: “Stoyan Stefanov”,
         “isbn10”: “1449320198”,
Using an API

   Update response
       HTTP/1.1 201 OK
       Date: Sun, 29 Jul 2012 23:26:49 GMT
       Server: Apache/2.2.22 (Ubuntu)
       X-Powered-By: PHP/5.3.10-1ubuntu3.2
       Location: http://example.com/books/decd0562
       Etag: “decd0562-2”
       Last-Modified: Sun, 29 Jul 2012 23:26:49 GMT
       Content-Length: 270
       Content-Type: application/hal+json

       {
           “_links”: {
                  “self”: {
                     “href”: “http://example.com/books/decd0562”
                  }
           },
           “author”: “Stoyan Stefanov”,
           “id”: “decd0562”,
           “isbn10”: “1449320198”,
Using an API

   DELETE
       Not safe
       Is idempotent
       Does not mean to remove the resource, but does
        mean to remove from public view.

         DELETE /books/decd0562 HTTP/1.1
         Host: example.com
         Accept-Encoding: identity, deflate, compress, gzip
         Accept: application/hal+json
         User-Agent: HTTPie/0.2.0
         If-Match: “decd0562-2”
Using an API

   DELETE response



          HTTP/1.1 204 No Content
          Date: Mon, 30 Jul 2012 00:01:44 GMT
          Server: Apache/2.2.22 (Ubuntu)
          X-Powered-By: PHP/5.3.10-1ubuntu3.2
          Content-Length: 0
          Content-Type: application/hal+json
Using an API

   HEAD
       Same as GET, but doesn't return the body
                  An example of use would be to check content
                    length before actually requesting it.
Using an API

   Status codes
       Informational (1xx)
       Successful (2xx)
       Redirection (3xx)
       Client error (4xx)
       Server error (5xx)
Using an API

   Common usage
       Most developers aren't building an API
       Using for sites and application content
       Leverage resources/services (Google Maps)
       Cut development time, add functionality
Using an API

   Resources for great APIs available
       Mashery.com
                    https://developer.mashery.com/apis
       Apigee.com
                    https://apigee.com/providers
       Google
                    https://developers.google.com



                     Let's take a look!!!
Using an API

   Documention tools
       Mashery http://mashery.github.com
                  I/O Docs – interactive API documentation
                  I/O Alfred – Alfred app to use some APIs
                  I/O Wraps – API client library generator
                  Oauth Signature Tool
                  Oauth 1.0 JS Testing Tool
                  AppMobi Sample Apps
Using an API

   Documentation tools
       apigee
                    Providers list
                    “Console” to experiment with APIs
                    “Console To-Go” to add your own API
                    Usergrid – Backend as a service to get mobile
                       apps running quickly.
                    O-Auth api
Using an API

   TO THE CODE!!!
Using an API

   Resources
       http://www.charlesproxy.com
       https://getfirebug.com
       http://www.httpie.org
       https://developer.mashery.com/apis
       https://apigee.com/providers
       https://developers.google.com
Using an API

   Thank You


                      Adam Culp
                      @adamculp
                 http://geekyboy.com


                Please rate this talk at:
                  http://joind.in/6739

More Related Content

PPTX
REST API Design for JAX-RS And Jersey
Stormpath
 
KEY
Rails Presentation (Anton Dmitriyev)
True-Vision
 
KEY
Plack at YAPC::NA 2010
Tatsuhiko Miyagawa
 
PPTX
Best practices for RESTful web service design
Ramin Orujov
 
PDF
Introduction to Retrofit
Kazuhiro Serizawa
 
PDF
API Design & Security in django
Tareque Hossain
 
PPT
External Data Access with jQuery
Doncho Minkov
 
PPTX
From ZERO to REST in an hour
Cisco DevNet
 
REST API Design for JAX-RS And Jersey
Stormpath
 
Rails Presentation (Anton Dmitriyev)
True-Vision
 
Plack at YAPC::NA 2010
Tatsuhiko Miyagawa
 
Best practices for RESTful web service design
Ramin Orujov
 
Introduction to Retrofit
Kazuhiro Serizawa
 
API Design & Security in django
Tareque Hossain
 
External Data Access with jQuery
Doncho Minkov
 
From ZERO to REST in an hour
Cisco DevNet
 

What's hot (18)

PDF
Getting Started with WebSockets and Server-Sent Events
Arun Gupta
 
KEY
Plack at OSCON 2010
Tatsuhiko Miyagawa
 
PDF
API Technical Writing
Sarah Maddox
 
PPT
Understanding REST
Nitin Pande
 
PDF
Frans Rosén Keynote at BSides Ahmedabad
Security BSides Ahmedabad
 
PPTX
The REST And Then Some
Nordic APIs
 
PDF
Building a desktop app with HTTP::Engine, SQLite and jQuery
Tatsuhiko Miyagawa
 
ODP
The Internet as Web Services: introduction to ReST
Bruno Kessler Foundation
 
PDF
Designing a beautiful REST json api
0x07de
 
PDF
JSON REST API for WordPress
Taylor Lovett
 
PDF
Opening up the Social Web - Standards that are bridging the Islands
Bastian Hofmann
 
PDF
Webpack Encore Symfony Live 2017 San Francisco
Ryan Weaver
 
PPTX
Tornado web
kurtiss
 
PPTX
Ruby in the Browser - RubyConf 2011
Ilya Grigorik
 
PDF
Maven 3.0 at Øredev
Matthew McCullough
 
PPTX
Ruby On Grape
Andrii Furmanets
 
PDF
MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...
MongoDB
 
PPTX
Design Beautiful REST + JSON APIs
Stormpath
 
Getting Started with WebSockets and Server-Sent Events
Arun Gupta
 
Plack at OSCON 2010
Tatsuhiko Miyagawa
 
API Technical Writing
Sarah Maddox
 
Understanding REST
Nitin Pande
 
Frans Rosén Keynote at BSides Ahmedabad
Security BSides Ahmedabad
 
The REST And Then Some
Nordic APIs
 
Building a desktop app with HTTP::Engine, SQLite and jQuery
Tatsuhiko Miyagawa
 
The Internet as Web Services: introduction to ReST
Bruno Kessler Foundation
 
Designing a beautiful REST json api
0x07de
 
JSON REST API for WordPress
Taylor Lovett
 
Opening up the Social Web - Standards that are bridging the Islands
Bastian Hofmann
 
Webpack Encore Symfony Live 2017 San Francisco
Ryan Weaver
 
Tornado web
kurtiss
 
Ruby in the Browser - RubyConf 2011
Ilya Grigorik
 
Maven 3.0 at Øredev
Matthew McCullough
 
Ruby On Grape
Andrii Furmanets
 
MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...
MongoDB
 
Design Beautiful REST + JSON APIs
Stormpath
 
Ad

Similar to Using an API (20)

PPT
eZ Publish REST API v2
Bertrand Dunogier
 
PPT
E zsc2012 rest-api-v2
Bertrand Dunogier
 
PDF
Introduction to Apigility
Engineor
 
PDF
Crafting APIs
Tatiana Al-Chueyr
 
PDF
Apigility – Lightning Fast API Development - OSSCamp 2014
OSSCube
 
PPTX
Survival Strategies for API Documentation: Presentation to Southwestern Ontar...
Tom Johnson
 
PPTX
ASP.NET Mvc 4 web api
Tiago Knoch
 
PDF
Apigility introduction v2 (glasgow php)
Engineor
 
PPTX
Gohan
Nachi Ueno
 
KEY
APIs Demystified
Brandon West
 
PDF
Mastering Microservices with Kong (DevoxxUK 2019)
Maarten Mulders
 
PDF
Talking to Web Services
DrupalcampAtlanta2012
 
KEY
Plack perl superglue for web frameworks and servers
Tatsuhiko Miyagawa
 
PDF
Unleash the power of HTTP with ASP.NET Web API
Filip W
 
PDF
Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...
ruyalarcon
 
PPTX
Google App Engine for PHP
Eric Johnson
 
PDF
High quality ap is with api platform
Nelson Kopliku
 
PDF
Using the new WordPress REST API
Caldera Labs
 
PPTX
Web Dev 21-01-2024.pptx
PARDHIVANNABATTULA
 
PPT
The future of server side JavaScript
Oleg Podsechin
 
eZ Publish REST API v2
Bertrand Dunogier
 
E zsc2012 rest-api-v2
Bertrand Dunogier
 
Introduction to Apigility
Engineor
 
Crafting APIs
Tatiana Al-Chueyr
 
Apigility – Lightning Fast API Development - OSSCamp 2014
OSSCube
 
Survival Strategies for API Documentation: Presentation to Southwestern Ontar...
Tom Johnson
 
ASP.NET Mvc 4 web api
Tiago Knoch
 
Apigility introduction v2 (glasgow php)
Engineor
 
Gohan
Nachi Ueno
 
APIs Demystified
Brandon West
 
Mastering Microservices with Kong (DevoxxUK 2019)
Maarten Mulders
 
Talking to Web Services
DrupalcampAtlanta2012
 
Plack perl superglue for web frameworks and servers
Tatsuhiko Miyagawa
 
Unleash the power of HTTP with ASP.NET Web API
Filip W
 
Fulfilling the Hypermedia Constraint via HTTP OPTIONS, The HTTP Vocabulary In...
ruyalarcon
 
Google App Engine for PHP
Eric Johnson
 
High quality ap is with api platform
Nelson Kopliku
 
Using the new WordPress REST API
Caldera Labs
 
Web Dev 21-01-2024.pptx
PARDHIVANNABATTULA
 
The future of server side JavaScript
Oleg Podsechin
 
Ad

More from Adam Culp (20)

PDF
Hypermedia
Adam Culp
 
PDF
Putting legacy to REST with middleware
Adam Culp
 
PDF
php-1701-a
Adam Culp
 
PDF
Release your refactoring superpower
Adam Culp
 
PDF
Managing Technical Debt
Adam Culp
 
PDF
Developing PHP Applications Faster
Adam Culp
 
PDF
Containing Quality
Adam Culp
 
PDF
Debugging elephpants
Adam Culp
 
PDF
Zend expressive workshop
Adam Culp
 
PDF
Expressive Microservice Framework Blastoff
Adam Culp
 
PDF
Foundations of Zend Framework
Adam Culp
 
PDF
Accidental professional
Adam Culp
 
PDF
Build great products
Adam Culp
 
PDF
Does Your Code Measure Up?
Adam Culp
 
PDF
Practical PHP Deployment with Jenkins
Adam Culp
 
PDF
Virtualizing Development
Adam Culp
 
PDF
Refactoring Legacy Code
Adam Culp
 
PDF
Deprecated: Foundations of Zend Framework 2
Adam Culp
 
PDF
Clean application development tutorial
Adam Culp
 
PDF
Refactoring 101
Adam Culp
 
Hypermedia
Adam Culp
 
Putting legacy to REST with middleware
Adam Culp
 
php-1701-a
Adam Culp
 
Release your refactoring superpower
Adam Culp
 
Managing Technical Debt
Adam Culp
 
Developing PHP Applications Faster
Adam Culp
 
Containing Quality
Adam Culp
 
Debugging elephpants
Adam Culp
 
Zend expressive workshop
Adam Culp
 
Expressive Microservice Framework Blastoff
Adam Culp
 
Foundations of Zend Framework
Adam Culp
 
Accidental professional
Adam Culp
 
Build great products
Adam Culp
 
Does Your Code Measure Up?
Adam Culp
 
Practical PHP Deployment with Jenkins
Adam Culp
 
Virtualizing Development
Adam Culp
 
Refactoring Legacy Code
Adam Culp
 
Deprecated: Foundations of Zend Framework 2
Adam Culp
 
Clean application development tutorial
Adam Culp
 
Refactoring 101
Adam Culp
 

Recently uploaded (20)

PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
PDF
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
 
PDF
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
PDF
agentic-ai-and-the-future-of-autonomous-systems.pdf
siddharthnetsavvies
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
This slide provides an overview Technology
mineshkharadi333
 
PDF
Doc9.....................................
SofiaCollazos
 
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
PDF
Software Development Company | KodekX
KodekX
 
PDF
Make GenAI investments go further with the Dell AI Factory - Infographic
Principled Technologies
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PDF
Enable Enterprise-Ready Security on IBM i Systems.pdf
Precisely
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PPTX
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
 
Chapter 2 Digital Image Fundamentals.pdf
Getnet Tigabie Askale -(GM)
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Why Your AI & Cybersecurity Hiring Still Misses the Mark in 2025
Virtual Employee Pvt. Ltd.
 
agentic-ai-and-the-future-of-autonomous-systems.pdf
siddharthnetsavvies
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
This slide provides an overview Technology
mineshkharadi333
 
Doc9.....................................
SofiaCollazos
 
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
Software Development Company | KodekX
KodekX
 
Make GenAI investments go further with the Dell AI Factory - Infographic
Principled Technologies
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
Enable Enterprise-Ready Security on IBM i Systems.pdf
Precisely
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 

Using an API

  • 2. Using an API  Tools  HTTPie  CURL  Charles – http://www.charlesproxy.com  Firebug – https://getfirebug.com
  • 3. Using an API  HTTPie  Great for debugging APIs rather than using cURL  http://www.httpie.org  Free  Requires Python POST /books HTTP/1.1 HOST: example.com Content-Type: application/hal+json Accept-Encoding: identity, deflate, compress, gzip Accept: application/hal+json User-Agent: HTTPie/0.2.0 { “author”: “Stoyan Stefanov”,
  • 4. Using an API  Charles  http://charlesproxy.com  Great for debugging AJAX and Flash AMF requests  Worth the $50 license fee, but (at least on Ubuntu) you can use it free, though it shuts down after 30 minutes.
  • 5. Using an API  cURL  Great to use via PHP, but for command line use HTTPie.  Firebug  Great for debugging from Firefox.  Others  I hear IE has an OK debugging tool like Firebug.  I have also heard Chrome has a great Firebug'ish tool also.
  • 6. Using an API  What is an API?  Application programming interface  A specification intended to be used as an interface by software components to communicate with each other. - wikipedia
  • 7. Using an API  API types (popular)  SOAP – Simple Object Access Protocol  REST – Representational State Transfer  (RFC 2616)  Javascript  Screen scrape
  • 8. Using an API  SOAP basics  Relies on XML as its message format.  Uses HTTP, SMTP, TCP, or JMS for transport, but usually HTTP.  Generally uses a WSDL (Web Services Description Language) configuration file making it easier to build for or connect to the API.  Cross platform and cross language.  Very structured – each action is defined (addUser, getUsers, getNewUsersSince, etc.)
  • 9. Using an API  Javascript basics  Client side execution  Communication from client to server  Usually methods are defined on server side (getThis, addThat, etc.)  Perception of interactivity (desktop feel)  Can be asynchronous  Used by Google Maps and others
  • 10. Using an API  Screen scrape basics  Not a true client/server api.  Relies on regular expression matching of content.  Usually done over HTTP using cURL.  Breaks when server content changes.  Must download all content, so may be slow and resource intensive.
  • 11. Using an API  REST basics (main focus for this talk)  Client-Server  Stateless – each request is complete and self contained (struggle with sessions and cookies)  Cacheable  Layered – client cannot tell if using end-server, allows load balancers, caches, logging, auth.  Uniform interface – decoupled from architecture  Methods – GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE, CONNECT
  • 12. Using an API  REST safe methods  No side effects on the server  GET & HEAD should make no other action than to retrieve.  Allows user agents to represent POST, PUT, and DELETE special. (most browsers do not support PUT and DELETE out of the box)
  • 13. Using an API  Idempotence  Operations that can be applied multiple times without changing the result. (Ex.- N>0 identical requests would have the same output)  GET, HEAD, PUT, and DELETE share this property  OPTIONS and TRACE are inherently idempotent.
  • 14. Using an API  GET  Safe and idempotent  No effect on the server GET /books/9790482c HTTP/1.1 Host: example.com Accept-Encoding: identity, deflate, compress, gzip Accept: application/hal+json User-Agent: HTTPie/0.2.0
  • 15. Using an API  GET response HTTP/1.1 200 OK Date: Wed, 08 Aug 2012 09:32:42 GMT Server: Apache/2.2.22 (Ubuntu) X-Powered-By: PHP/5.3.10-1ubuntu3.2 ETag: “9790482c-1” Last-Modified: Wed, 08 Aug 2012 04:14:30 GMT Content-Length: 254 Content-Type: application/hal+json { “_links”: { “self”: { “href”: “http://example.com/books/9790482c” } }, “author”: “Luke Welling, Laura Thomson”, “id”: “9790482c”, “isbn10”: “0672329166”,
  • 16. Using an API  POST  Not safe  Not idempotent (same post multiple times could have different effects on server)  Used to create resource  Is often used to also update a resource, though PUT is more for updating.
  • 17. Using an API  POST example POST /books HTTP/1.1 HOST: example.com Content-Type: application/hal+json Accept-Encoding: identity, deflate, compress, gzip Accept: application/hal+json User-Agent: HTTPie/0.2.0 { “author”: “Stoyan Stefanov”, “isbn10”: “1449320198”, “isbn13”: “9781449320195”, “publisher”: “O'Reilly Media”, “title”: “Javascript for PHP Developers”, “year”: 2012 }
  • 18. Using an API  Created Response HTTP/1.1 201 Created Date: Sun, 29 Jul 2012 23:26:49 GMT Server: Apache/2.2.22 (Ubuntu) X-Powered-By: PHP/5.3.10-1ubuntu3.2 Location: http://example.com/books/decd0562 Etag: “decd0562-1” Last-Modified: Sun, 29 Jul 2012 23:26:49 GMT Content-Length: 239 Content-Type: application/hal+json { “_links”: { “self”: { “href”: “http://example.com/books/decd0562” } }, “author”: “Stoyan Stefanov”, “id”: “decd0562”, “isbn10”: “1449320198”,
  • 19. Using an API  PUT  Not safe  But is idempotent  Primarily an update action, but can also be used to create though POST should be used for that.
  • 20. Using an API  Sample PUT PUT /books/decd0562 HTTP/1.1 HOST: example.com Content-Type: application/hal+json Accept-Encoding: identity, deflate, compress, gzip If-Match: “decd0562-1” Accept: application/hal+json User-Agent: HTTPie/0.2.0 { “_links”: { “self”: { “href”: “http://example.com/books/decd0562” } } “author”: “Stoyan Stefanov”, “isbn10”: “1449320198”,
  • 21. Using an API  Update response HTTP/1.1 201 OK Date: Sun, 29 Jul 2012 23:26:49 GMT Server: Apache/2.2.22 (Ubuntu) X-Powered-By: PHP/5.3.10-1ubuntu3.2 Location: http://example.com/books/decd0562 Etag: “decd0562-2” Last-Modified: Sun, 29 Jul 2012 23:26:49 GMT Content-Length: 270 Content-Type: application/hal+json { “_links”: { “self”: { “href”: “http://example.com/books/decd0562” } }, “author”: “Stoyan Stefanov”, “id”: “decd0562”, “isbn10”: “1449320198”,
  • 22. Using an API  DELETE  Not safe  Is idempotent  Does not mean to remove the resource, but does mean to remove from public view. DELETE /books/decd0562 HTTP/1.1 Host: example.com Accept-Encoding: identity, deflate, compress, gzip Accept: application/hal+json User-Agent: HTTPie/0.2.0 If-Match: “decd0562-2”
  • 23. Using an API  DELETE response HTTP/1.1 204 No Content Date: Mon, 30 Jul 2012 00:01:44 GMT Server: Apache/2.2.22 (Ubuntu) X-Powered-By: PHP/5.3.10-1ubuntu3.2 Content-Length: 0 Content-Type: application/hal+json
  • 24. Using an API  HEAD  Same as GET, but doesn't return the body  An example of use would be to check content length before actually requesting it.
  • 25. Using an API  Status codes  Informational (1xx)  Successful (2xx)  Redirection (3xx)  Client error (4xx)  Server error (5xx)
  • 26. Using an API  Common usage  Most developers aren't building an API  Using for sites and application content  Leverage resources/services (Google Maps)  Cut development time, add functionality
  • 27. Using an API  Resources for great APIs available  Mashery.com  https://developer.mashery.com/apis  Apigee.com  https://apigee.com/providers  Google  https://developers.google.com Let's take a look!!!
  • 28. Using an API  Documention tools  Mashery http://mashery.github.com  I/O Docs – interactive API documentation  I/O Alfred – Alfred app to use some APIs  I/O Wraps – API client library generator  Oauth Signature Tool  Oauth 1.0 JS Testing Tool  AppMobi Sample Apps
  • 29. Using an API  Documentation tools  apigee  Providers list  “Console” to experiment with APIs  “Console To-Go” to add your own API  Usergrid – Backend as a service to get mobile apps running quickly.  O-Auth api
  • 30. Using an API  TO THE CODE!!!
  • 31. Using an API  Resources  http://www.charlesproxy.com  https://getfirebug.com  http://www.httpie.org  https://developer.mashery.com/apis  https://apigee.com/providers  https://developers.google.com
  • 32. Using an API  Thank You Adam Culp @adamculp http://geekyboy.com Please rate this talk at: http://joind.in/6739