SlideShare a Scribd company logo
1 of 21
Using Data That Isn’t Yours
How to consume web services to augment your web sites and apps.




                     An Adventure With Stubby
Stubby

         stubby@cogsprocket.net

             StubbyTheGreat
What’s a Web Service

           A web service is a component in a web application
     that allows the owner to share data with remote applications.

                     It’s like a drive-thru library...
“If you want my books I’ll give you a chute where you can pick them up.”
Where Are They?
                   EVERYWHERE.
    Twitter                         Facebook

Google Calendar                     YouTube

   Dribbble                         Your Blog
Different Kinds of Services

• REST - Representational State Transfer
 • Ruby on Rails does this by design
•   SOAP - Simple Object Access Protocol
 • Native to .NET, not well supported in other platforms
•   RSS - Really Simple Syndication
 • XML service that power blog subs and podcasts
Know How To Get It


•Find the service you want to consume
• Read the documentation
 • https://dev.twitter.com/docs
Things To Look Out For

• Services with poor or no documentation
• Request rate limits
• Data return formats
• Service types not supported by your language
The Basics...

•Check the API for the service you want to consume
• Pull the data into your application
• Iterate through the data returned
• Output or store the data
• Super duper easy, right?
The Anatamy Of A Request
http://api.twitter.com/1/statuses/user_timeline.json?screen_name=<screen_name>



          How To Make The Request
                     $data = file_get_contents(<api_url>);
What You’ll Likely Get

            A String

Yeah... You were probably hoping
  for something more exotic....
Bad news...

A string of data is something, but it’s
 not anything super duper useful...
What You’ll Likely Get
              Here’s a problem... Let’s fix it with objects.


•JSON - Javascript Object Notation
 • Make the data readable with json_decode()
• XML - Extensible Markup Language
 • Make the data readable with simplexml_load_string()
What JSON Looks Like


           $results->created_at
           $results->text
What XML Looks Like


           $results->created_at
           $results->text
What’s Next?!
Now that you’ve got an object you can totally iterate through it.


                 // Super-scary iteration
                 for($i=0; $i <= 15; $i++) {

                     // Do something awesome

                 }
“for()” Can Be Scary
        You can totally use foreach()

    // Less-than-scary iteration
    foreach($results as $result) {

         // Do something awesome

    }
foreach() will iterate through everything
How I Like To Do it...
                     You can totally use foreach()

                 // Madman iteration
                 foreach($results as $result) {

                      $this->{$value} = $result->...

                 }
Makes $object->VariableName... (‘Cause I treat code like objects)
What To Do With The Data

• Output it!
 • You got it for a reason, give it a good ol’ “echo” and let the world see
• Store it!
 • Probably a good idea to store any data for at least 5 minutes...
What Could Go Wrong?


         The service could
          be unavailable...
What Could Go Wrong?


The remote end could
  block your access
Be Like Stubby
                             Behave yourself...


• Cache your data
• Limit the number of requests you make per hour
• Use a local iterator
 • Local iterators duplicate the service and handle caching

More Related Content

What's hot

Advanced WordPress Development Environments
Advanced WordPress Development EnvironmentsAdvanced WordPress Development Environments
Advanced WordPress Development Environments
Beau Lebens
 

What's hot (18)

Introduction to Parse backend for mobile developers
Introduction to Parse backend for mobile developersIntroduction to Parse backend for mobile developers
Introduction to Parse backend for mobile developers
 
WordPress as the Backbone(.js)
WordPress as the Backbone(.js)WordPress as the Backbone(.js)
WordPress as the Backbone(.js)
 
The JSON REST API for WordPress
The JSON REST API for WordPressThe JSON REST API for WordPress
The JSON REST API for WordPress
 
Tide - The missing web framework
Tide - The missing web frameworkTide - The missing web framework
Tide - The missing web framework
 
Advanced WordPress Development Environments
Advanced WordPress Development EnvironmentsAdvanced WordPress Development Environments
Advanced WordPress Development Environments
 
Zero to Hipster with the M.I.K.E. Stack
Zero to Hipster with the M.I.K.E. StackZero to Hipster with the M.I.K.E. Stack
Zero to Hipster with the M.I.K.E. Stack
 
The costs of cloud computing
The costs of cloud computingThe costs of cloud computing
The costs of cloud computing
 
Learning jQuery in 30 minutes
Learning jQuery in 30 minutesLearning jQuery in 30 minutes
Learning jQuery in 30 minutes
 
bcgr3-jquery
bcgr3-jquerybcgr3-jquery
bcgr3-jquery
 
Automating Content Import
Automating Content ImportAutomating Content Import
Automating Content Import
 
Plone pwns
Plone pwnsPlone pwns
Plone pwns
 
Intro to CouchDB
Intro to CouchDBIntro to CouchDB
Intro to CouchDB
 
kumogata-template の紹介
kumogata-template の紹介kumogata-template の紹介
kumogata-template の紹介
 
CouchDB in The Room
CouchDB in The RoomCouchDB in The Room
CouchDB in The Room
 
Voyage by example
Voyage by exampleVoyage by example
Voyage by example
 
RESTful Web Services
RESTful Web ServicesRESTful Web Services
RESTful Web Services
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
Automation using Scripting and the Canvas API
Automation using Scripting and the Canvas APIAutomation using Scripting and the Canvas API
Automation using Scripting and the Canvas API
 

Similar to Using Data That Isn't Yours

Prophet - Beijing Perl Workshop
Prophet - Beijing Perl WorkshopProphet - Beijing Perl Workshop
Prophet - Beijing Perl Workshop
Jesse Vincent
 
My site is slow
My site is slowMy site is slow
My site is slow
hernanibf
 
Devops kc meetup_5_20_2013
Devops kc meetup_5_20_2013Devops kc meetup_5_20_2013
Devops kc meetup_5_20_2013
Aaron Blythe
 
SXSW 2012 JavaScript MythBusters
SXSW 2012 JavaScript MythBustersSXSW 2012 JavaScript MythBusters
SXSW 2012 JavaScript MythBusters
Elena-Oana Tabaranu
 

Similar to Using Data That Isn't Yours (20)

Drupal 8: A story of growing up and getting off the island
Drupal 8: A story of growing up and getting off the islandDrupal 8: A story of growing up and getting off the island
Drupal 8: A story of growing up and getting off the island
 
REST APIs in Laravel 101
REST APIs in Laravel 101REST APIs in Laravel 101
REST APIs in Laravel 101
 
Django at Scale
Django at ScaleDjango at Scale
Django at Scale
 
API Design Antipatterns - APICon SF
API Design Antipatterns - APICon SFAPI Design Antipatterns - APICon SF
API Design Antipatterns - APICon SF
 
flickr's architecture & php
flickr's architecture & php flickr's architecture & php
flickr's architecture & php
 
Dapper: the microORM that will change your life
Dapper: the microORM that will change your lifeDapper: the microORM that will change your life
Dapper: the microORM that will change your life
 
All of Javascript
All of JavascriptAll of Javascript
All of Javascript
 
Splunk bsides
Splunk bsidesSplunk bsides
Splunk bsides
 
Prophet - Beijing Perl Workshop
Prophet - Beijing Perl WorkshopProphet - Beijing Perl Workshop
Prophet - Beijing Perl Workshop
 
My site is slow
My site is slowMy site is slow
My site is slow
 
Agile Data: Building Hadoop Analytics Applications
Agile Data: Building Hadoop Analytics ApplicationsAgile Data: Building Hadoop Analytics Applications
Agile Data: Building Hadoop Analytics Applications
 
SPSNH 2014 - The SharePoint & jQueryGuide
SPSNH 2014 - The SharePoint & jQueryGuideSPSNH 2014 - The SharePoint & jQueryGuide
SPSNH 2014 - The SharePoint & jQueryGuide
 
A tale of two proxies
A tale of two proxiesA tale of two proxies
A tale of two proxies
 
Web Service and Mobile Integrated Day I
Web Service and Mobile Integrated Day IWeb Service and Mobile Integrated Day I
Web Service and Mobile Integrated Day I
 
Exploring the Semantic Web
Exploring the Semantic WebExploring the Semantic Web
Exploring the Semantic Web
 
Devops kc meetup_5_20_2013
Devops kc meetup_5_20_2013Devops kc meetup_5_20_2013
Devops kc meetup_5_20_2013
 
My Site is slow - Drupal Camp London 2013
My Site is slow - Drupal Camp London 2013My Site is slow - Drupal Camp London 2013
My Site is slow - Drupal Camp London 2013
 
PHP and Platform Independance in the Cloud
PHP and Platform Independance in the CloudPHP and Platform Independance in the Cloud
PHP and Platform Independance in the Cloud
 
SXSW 2012 JavaScript MythBusters
SXSW 2012 JavaScript MythBustersSXSW 2012 JavaScript MythBusters
SXSW 2012 JavaScript MythBusters
 
Yahoo is open to developers
Yahoo is open to developersYahoo is open to developers
Yahoo is open to developers
 

Recently uploaded

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Recently uploaded (20)

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

Using Data That Isn't Yours

  • 1. Using Data That Isn’t Yours How to consume web services to augment your web sites and apps. An Adventure With Stubby
  • 2. Stubby stubby@cogsprocket.net StubbyTheGreat
  • 3. What’s a Web Service A web service is a component in a web application that allows the owner to share data with remote applications. It’s like a drive-thru library... “If you want my books I’ll give you a chute where you can pick them up.”
  • 4. Where Are They? EVERYWHERE. Twitter Facebook Google Calendar YouTube Dribbble Your Blog
  • 5. Different Kinds of Services • REST - Representational State Transfer • Ruby on Rails does this by design • SOAP - Simple Object Access Protocol • Native to .NET, not well supported in other platforms • RSS - Really Simple Syndication • XML service that power blog subs and podcasts
  • 6. Know How To Get It •Find the service you want to consume • Read the documentation • https://dev.twitter.com/docs
  • 7. Things To Look Out For • Services with poor or no documentation • Request rate limits • Data return formats • Service types not supported by your language
  • 8. The Basics... •Check the API for the service you want to consume • Pull the data into your application • Iterate through the data returned • Output or store the data • Super duper easy, right?
  • 9. The Anatamy Of A Request http://api.twitter.com/1/statuses/user_timeline.json?screen_name=<screen_name> How To Make The Request $data = file_get_contents(<api_url>);
  • 10. What You’ll Likely Get A String Yeah... You were probably hoping for something more exotic....
  • 11. Bad news... A string of data is something, but it’s not anything super duper useful...
  • 12. What You’ll Likely Get Here’s a problem... Let’s fix it with objects. •JSON - Javascript Object Notation • Make the data readable with json_decode() • XML - Extensible Markup Language • Make the data readable with simplexml_load_string()
  • 13. What JSON Looks Like $results->created_at $results->text
  • 14. What XML Looks Like $results->created_at $results->text
  • 15. What’s Next?! Now that you’ve got an object you can totally iterate through it. // Super-scary iteration for($i=0; $i <= 15; $i++) { // Do something awesome }
  • 16. “for()” Can Be Scary You can totally use foreach() // Less-than-scary iteration foreach($results as $result) { // Do something awesome } foreach() will iterate through everything
  • 17. How I Like To Do it... You can totally use foreach() // Madman iteration foreach($results as $result) { $this->{$value} = $result->... } Makes $object->VariableName... (‘Cause I treat code like objects)
  • 18. What To Do With The Data • Output it! • You got it for a reason, give it a good ol’ “echo” and let the world see • Store it! • Probably a good idea to store any data for at least 5 minutes...
  • 19. What Could Go Wrong? The service could be unavailable...
  • 20. What Could Go Wrong? The remote end could block your access
  • 21. Be Like Stubby Behave yourself... • Cache your data • Limit the number of requests you make per hour • Use a local iterator • Local iterators duplicate the service and handle caching

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n