SlideShare une entreprise Scribd logo
1  sur  49
Télécharger pour lire hors ligne
Building Brilliant APIs
                         that bloody work




Monday, 4 October 2010
Jason Fry


                             @fry15
                          jasonfry.co.uk




Monday, 4 October 2010
Ben Collier



                @ben_c            @redsign
              bencollier.net     redsign.co.uk



Monday, 4 October 2010
Our Inspiration?


                    • Working with a terrible API



Monday, 4 October 2010
Our Inspiration?
                <xml>
                         <head>
                         </head>
                         <body>
                           <response>Random Useless Text</response>
                         </body>
                  </xml>



Monday, 4 October 2010
Why Build APIs?


                    • Mobile Applications
                    • Rich Web Applcations


Monday, 4 October 2010
Mobile Applications


                    • Enables your app to talk to your service
                    • Don’t just open database connections


Monday, 4 October 2010
Websites


                    • Optimisation
                    • Caching


Monday, 4 October 2010
Websites

                    • Twitter
                     • http://engineering.twitter.com
                    • Facebook


Monday, 4 October 2010
But...


                         “I’m not planning on building an API yet so
                                     why should I care?”




Monday, 4 October 2010
What Makes a Brilliant
                                API?



Monday, 4 October 2010
Naming

               • Use descriptive meaningful names
               • Don’t be afraid to use really long names
                         http://ws.audioscrobbler.com/2.0/?
                         method=user.gettopalbums&user=rj




Monday, 4 October 2010
Building URLs

                    • Base URI
                     • e.g. api.twitter.com/v2/
                    • Method
                     • e.g. statuses/user_timeline.xml

Monday, 4 October 2010
Responses


                    • XML / JSON
                    • Clear structure


Monday, 4 October 2010
Responses
         <topalbums user="RJ" type="overall">
          <album rank="1">
            <name>Images and Words</name>
            <playcount>174</playcount>
            <mbid>f20971f2-c8ad-4d26-91ab-730f6dedafb2</mbid>
            <url>
             http://www.last.fm/music/Dream+Theater/Images+and+Words
            </url>
            <artist>
             <name>Dream Theater</name>
             <mbid>28503ab7-8bf2-4666-a7bd-2644bfc7cb1d</mbid>
             <url>http://www.last.fm/music/Dream+Theater</url>
            </artist>
            <image size="small">...</image>
            <image size="medium">...</image>
            <image size="large">...</image>
          </album>
         </topalbums>

Monday, 4 October 2010
Error Codes

                    • Numbers which mean something
                    • Success, error
                     • Missing parameter x
                     • Parameter x must be 3 characters long
                     • etc etc

Monday, 4 October 2010
Types of APIs


               • SOAP

               • RESTful




Monday, 4 October 2010
Types of APIs


                         SOAP
                         Simple Object Access Protocol




Monday, 4 October 2010
Types of APIs


                         RESTful
                         Representable State Transfer




Monday, 4 October 2010
RESTful

                         Based on HTTP Request protocol




Monday, 4 October 2010
RESTful

                         Based on HTTP Request protocol


                 PUT          DELETE         GET          POST




Monday, 4 October 2010
RESTful

                         Based on HTTP Request protocol


                              GET             POST




                                     DELETE
                                      PUT




Monday, 4 October 2010
RESTful

                         Based on HTTP Request protocol


                              GET            POST




Monday, 4 October 2010
Versioning

                    • API version in URL
                    • eg http://locationtextvideoapi.com/2.0/
                    • Allows backwackwards compatibility
                         without sacrificing future versions




Monday, 4 October 2010
Authentication

                    • Two choices
                     • OAuth
                     • Basic (http / session)


Monday, 4 October 2010
Basic Authentication




Monday, 4 October 2010
Basic Authentication


                         Username   Password




Monday, 4 October 2010
Basic Authentication


                         Username     Password


                                    5f4dcc3b5aa765d6
                                    1d8327deb882cf99




Monday, 4 October 2010
Basic Authentication


                         Username     Password


                                    5f4dcc3b5aa765d6
                                    1d8327deb882cf99




Monday, 4 October 2010
OAuth


                         Open Standard   Greater Control   User Safety




Monday, 4 October 2010
Responses




Monday, 4 October 2010
Responses



                         XML      JSON     .plist




Monday, 4 October 2010
Responses

                                  Objects




                         XML       JSON     .plist




Monday, 4 October 2010
XML


                    • PHP DomDocument
                    • PEAR Library for exporting straight from
                         MySQL




Monday, 4 October 2010
JSON




Monday, 4 October 2010
JSON
                              $arr = 
            array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5);




Monday, 4 October 2010
JSON
                              $arr = 
            array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5);


                         echo json_encode($arr);




Monday, 4 October 2010
JSON
                              $arr = 
            array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5);


                         echo json_encode($arr);



                         {"a":1,"b":2,"c":3,"d":4,"e":5}




Monday, 4 October 2010
UGC


                   Images



                                     Encoding.com
                  Audio /
                            FFMpeg
                   Video
                                      Vzaar.com

Monday, 4 October 2010
Media Links


                    • Link in a logical way
                    • Eg: http://apisrock.com/64x64/23456.jpg


Monday, 4 October 2010
Location Aware




                         Location based searching can be a bitch




Monday, 4 October 2010
Documentation




Monday, 4 October 2010
Documentation


                    • Do it



Monday, 4 October 2010
Documentation


                    • Do it
                    • Even if it’s not public facing- do it!


Monday, 4 October 2010
Hosting


                    • Build in PHP / MySQL
                     • Deployable on Amazon Web Services


Monday, 4 October 2010
Some Good Examples


                    • Last.fm
                    • Twitter
                    • Foursquare


Monday, 4 October 2010
Any questions?


                    • Good.



Monday, 4 October 2010
Thanks
                     Ben Collier            Jason Fry
                   me@bencollier.net   jason@jasonfry.co.uk
                       @ben_c                 @fry15




Monday, 4 October 2010
Thanks
                     Ben Collier            Jason Fry
                   me@bencollier.net   jason@jasonfry.co.uk
                       @ben_c                 @fry15
  Bubble Image- http://www.flickr.com/photos/philippbunge/
    Hammock- http://www.flickr.com/photos/ironrodart/
     Padlock- http://www.flickr.com/photos/sooperkuh/
      Binary Windows - http://www.flickr.com/photos/
                       9619972@N08/
   Boxing Lemur - http://www.flickr.com/photos/e_phots/
                 Earth from Space - NASA
Monday, 4 October 2010

Contenu connexe

Similaire à Building Brilliant APIs

Sdforum 11-04-2010
Sdforum 11-04-2010Sdforum 11-04-2010
Sdforum 11-04-2010
Ted Dunning
 
Large problems, Mostly Solved
Large problems, Mostly SolvedLarge problems, Mostly Solved
Large problems, Mostly Solved
ericholscher
 
Using+javascript+to+build+native+i os+applications
Using+javascript+to+build+native+i os+applicationsUsing+javascript+to+build+native+i os+applications
Using+javascript+to+build+native+i os+applications
Muhammad Ikram Ul Haq
 
Html5/CSS3 in shanghai 2010
Html5/CSS3 in shanghai 2010Html5/CSS3 in shanghai 2010
Html5/CSS3 in shanghai 2010
Zi Bin Cheah
 

Similaire à Building Brilliant APIs (20)

ExpressionEngine FUGN presentation
ExpressionEngine FUGN presentationExpressionEngine FUGN presentation
ExpressionEngine FUGN presentation
 
BRAINREPUBLIC - Powered by no-SQL
BRAINREPUBLIC - Powered by no-SQLBRAINREPUBLIC - Powered by no-SQL
BRAINREPUBLIC - Powered by no-SQL
 
let's talk web standards
let's talk web standardslet's talk web standards
let's talk web standards
 
In depth with html5 java2days 2010
In depth with html5 java2days 2010In depth with html5 java2days 2010
In depth with html5 java2days 2010
 
Opening up the Social Web - Standards that are bridging the Islands
Opening up the Social Web - Standards that are bridging the Islands Opening up the Social Web - Standards that are bridging the Islands
Opening up the Social Web - Standards that are bridging the Islands
 
OSMC 2010 | OpenNMS Kickstart by Ronny Trommer
OSMC 2010 | OpenNMS Kickstart by Ronny TrommerOSMC 2010 | OpenNMS Kickstart by Ronny Trommer
OSMC 2010 | OpenNMS Kickstart by Ronny Trommer
 
ツイキャス・東京ユーザー会 資料
ツイキャス・東京ユーザー会 資料ツイキャス・東京ユーザー会 資料
ツイキャス・東京ユーザー会 資料
 
SD Forum 11 04-2010
SD Forum 11 04-2010SD Forum 11 04-2010
SD Forum 11 04-2010
 
Sdforum 11-04-2010
Sdforum 11-04-2010Sdforum 11-04-2010
Sdforum 11-04-2010
 
Debugging your JavaScript
Debugging your JavaScriptDebugging your JavaScript
Debugging your JavaScript
 
Enterprise Drupal
Enterprise DrupalEnterprise Drupal
Enterprise Drupal
 
Large problems, Mostly Solved
Large problems, Mostly SolvedLarge problems, Mostly Solved
Large problems, Mostly Solved
 
Persistence Smoothie: Blending SQL and NoSQL (RubyNation Edition)
Persistence  Smoothie: Blending SQL and NoSQL (RubyNation Edition)Persistence  Smoothie: Blending SQL and NoSQL (RubyNation Edition)
Persistence Smoothie: Blending SQL and NoSQL (RubyNation Edition)
 
Crowd-sourced Automated Firefox UI Testing
Crowd-sourced Automated Firefox UI TestingCrowd-sourced Automated Firefox UI Testing
Crowd-sourced Automated Firefox UI Testing
 
MongoDB on Rails (and Ruby)
MongoDB on Rails (and Ruby)MongoDB on Rails (and Ruby)
MongoDB on Rails (and Ruby)
 
Using+javascript+to+build+native+i os+applications
Using+javascript+to+build+native+i os+applicationsUsing+javascript+to+build+native+i os+applications
Using+javascript+to+build+native+i os+applications
 
Meet Couch DB
Meet Couch DBMeet Couch DB
Meet Couch DB
 
Is these a bug
Is these a bugIs these a bug
Is these a bug
 
livedoor における Twitter 活用事例と個人的趣味な小ネタたちのご紹介
livedoor における Twitter 活用事例と個人的趣味な小ネタたちのご紹介livedoor における Twitter 活用事例と個人的趣味な小ネタたちのご紹介
livedoor における Twitter 活用事例と個人的趣味な小ネタたちのご紹介
 
Html5/CSS3 in shanghai 2010
Html5/CSS3 in shanghai 2010Html5/CSS3 in shanghai 2010
Html5/CSS3 in shanghai 2010
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Dernier (20)

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
 
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 🐘
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 

Building Brilliant APIs

  • 1. Building Brilliant APIs that bloody work Monday, 4 October 2010
  • 2. Jason Fry @fry15 jasonfry.co.uk Monday, 4 October 2010
  • 3. Ben Collier @ben_c @redsign bencollier.net redsign.co.uk Monday, 4 October 2010
  • 4. Our Inspiration? • Working with a terrible API Monday, 4 October 2010
  • 5. Our Inspiration? <xml> <head> </head> <body> <response>Random Useless Text</response> </body> </xml> Monday, 4 October 2010
  • 6. Why Build APIs? • Mobile Applications • Rich Web Applcations Monday, 4 October 2010
  • 7. Mobile Applications • Enables your app to talk to your service • Don’t just open database connections Monday, 4 October 2010
  • 8. Websites • Optimisation • Caching Monday, 4 October 2010
  • 9. Websites • Twitter • http://engineering.twitter.com • Facebook Monday, 4 October 2010
  • 10. But... “I’m not planning on building an API yet so why should I care?” Monday, 4 October 2010
  • 11. What Makes a Brilliant API? Monday, 4 October 2010
  • 12. Naming • Use descriptive meaningful names • Don’t be afraid to use really long names http://ws.audioscrobbler.com/2.0/? method=user.gettopalbums&user=rj Monday, 4 October 2010
  • 13. Building URLs • Base URI • e.g. api.twitter.com/v2/ • Method • e.g. statuses/user_timeline.xml Monday, 4 October 2010
  • 14. Responses • XML / JSON • Clear structure Monday, 4 October 2010
  • 15. Responses <topalbums user="RJ" type="overall"> <album rank="1"> <name>Images and Words</name> <playcount>174</playcount> <mbid>f20971f2-c8ad-4d26-91ab-730f6dedafb2</mbid> <url> http://www.last.fm/music/Dream+Theater/Images+and+Words </url> <artist> <name>Dream Theater</name> <mbid>28503ab7-8bf2-4666-a7bd-2644bfc7cb1d</mbid> <url>http://www.last.fm/music/Dream+Theater</url> </artist> <image size="small">...</image> <image size="medium">...</image> <image size="large">...</image> </album> </topalbums> Monday, 4 October 2010
  • 16. Error Codes • Numbers which mean something • Success, error • Missing parameter x • Parameter x must be 3 characters long • etc etc Monday, 4 October 2010
  • 17. Types of APIs • SOAP • RESTful Monday, 4 October 2010
  • 18. Types of APIs SOAP Simple Object Access Protocol Monday, 4 October 2010
  • 19. Types of APIs RESTful Representable State Transfer Monday, 4 October 2010
  • 20. RESTful Based on HTTP Request protocol Monday, 4 October 2010
  • 21. RESTful Based on HTTP Request protocol PUT DELETE GET POST Monday, 4 October 2010
  • 22. RESTful Based on HTTP Request protocol GET POST DELETE PUT Monday, 4 October 2010
  • 23. RESTful Based on HTTP Request protocol GET POST Monday, 4 October 2010
  • 24. Versioning • API version in URL • eg http://locationtextvideoapi.com/2.0/ • Allows backwackwards compatibility without sacrificing future versions Monday, 4 October 2010
  • 25. Authentication • Two choices • OAuth • Basic (http / session) Monday, 4 October 2010
  • 27. Basic Authentication Username Password Monday, 4 October 2010
  • 28. Basic Authentication Username Password 5f4dcc3b5aa765d6 1d8327deb882cf99 Monday, 4 October 2010
  • 29. Basic Authentication Username Password 5f4dcc3b5aa765d6 1d8327deb882cf99 Monday, 4 October 2010
  • 30. OAuth Open Standard Greater Control User Safety Monday, 4 October 2010
  • 32. Responses XML JSON .plist Monday, 4 October 2010
  • 33. Responses Objects XML JSON .plist Monday, 4 October 2010
  • 34. XML • PHP DomDocument • PEAR Library for exporting straight from MySQL Monday, 4 October 2010
  • 36. JSON $arr =  array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5); Monday, 4 October 2010
  • 37. JSON $arr =  array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5); echo json_encode($arr); Monday, 4 October 2010
  • 38. JSON $arr =  array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5); echo json_encode($arr); {"a":1,"b":2,"c":3,"d":4,"e":5} Monday, 4 October 2010
  • 39. UGC Images Encoding.com Audio / FFMpeg Video Vzaar.com Monday, 4 October 2010
  • 40. Media Links • Link in a logical way • Eg: http://apisrock.com/64x64/23456.jpg Monday, 4 October 2010
  • 41. Location Aware Location based searching can be a bitch Monday, 4 October 2010
  • 43. Documentation • Do it Monday, 4 October 2010
  • 44. Documentation • Do it • Even if it’s not public facing- do it! Monday, 4 October 2010
  • 45. Hosting • Build in PHP / MySQL • Deployable on Amazon Web Services Monday, 4 October 2010
  • 46. Some Good Examples • Last.fm • Twitter • Foursquare Monday, 4 October 2010
  • 47. Any questions? • Good. Monday, 4 October 2010
  • 48. Thanks Ben Collier Jason Fry me@bencollier.net jason@jasonfry.co.uk @ben_c @fry15 Monday, 4 October 2010
  • 49. Thanks Ben Collier Jason Fry me@bencollier.net jason@jasonfry.co.uk @ben_c @fry15 Bubble Image- http://www.flickr.com/photos/philippbunge/ Hammock- http://www.flickr.com/photos/ironrodart/ Padlock- http://www.flickr.com/photos/sooperkuh/ Binary Windows - http://www.flickr.com/photos/ 9619972@N08/ Boxing Lemur - http://www.flickr.com/photos/e_phots/ Earth from Space - NASA Monday, 4 October 2010