Building Brilliant APIs

2,335 views
2,220 views

Published on

Mine and Jason's talk from BarCampBrighton 5 about building brilliant APIs that bloody work.

Probably won't make sense without having been there..

Any questions give myself (@ben_c) or Jason (@fry15) a shout on twitter.

Published in: Technology, Design
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,335
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Building Brilliant APIs

  1. 1. Building Brilliant APIs that bloody workMonday, 4 October 2010
  2. 2. Jason Fry @fry15 jasonfry.co.ukMonday, 4 October 2010
  3. 3. Ben Collier @ben_c @redsign bencollier.net redsign.co.ukMonday, 4 October 2010
  4. 4. Our Inspiration? • Working with a terrible APIMonday, 4 October 2010
  5. 5. Our Inspiration? <xml> <head> </head> <body> <response>Random Useless Text</response> </body> </xml>Monday, 4 October 2010
  6. 6. Why Build APIs? • Mobile Applications • Rich Web ApplcationsMonday, 4 October 2010
  7. 7. Mobile Applications • Enables your app to talk to your service • Don’t just open database connectionsMonday, 4 October 2010
  8. 8. Websites • Optimisation • CachingMonday, 4 October 2010
  9. 9. Websites • Twitter • http://engineering.twitter.com • FacebookMonday, 4 October 2010
  10. 10. But... “I’m not planning on building an API yet so why should I care?”Monday, 4 October 2010
  11. 11. What Makes a Brilliant API?Monday, 4 October 2010
  12. 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=rjMonday, 4 October 2010
  13. 13. Building URLs • Base URI • e.g. api.twitter.com/v2/ • Method • e.g. statuses/user_timeline.xmlMonday, 4 October 2010
  14. 14. Responses • XML / JSON • Clear structureMonday, 4 October 2010
  15. 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. 16. Error Codes • Numbers which mean something • Success, error • Missing parameter x • Parameter x must be 3 characters long • etc etcMonday, 4 October 2010
  17. 17. Types of APIs • SOAP • RESTfulMonday, 4 October 2010
  18. 18. Types of APIs SOAP Simple Object Access ProtocolMonday, 4 October 2010
  19. 19. Types of APIs RESTful Representable State TransferMonday, 4 October 2010
  20. 20. RESTful Based on HTTP Request protocolMonday, 4 October 2010
  21. 21. RESTful Based on HTTP Request protocol PUT DELETE GET POSTMonday, 4 October 2010
  22. 22. RESTful Based on HTTP Request protocol GET POST DELETE PUTMonday, 4 October 2010
  23. 23. RESTful Based on HTTP Request protocol GET POSTMonday, 4 October 2010
  24. 24. Versioning • API version in URL • eg http://locationtextvideoapi.com/2.0/ • Allows backwackwards compatibility without sacrificing future versionsMonday, 4 October 2010
  25. 25. Authentication • Two choices • OAuth • Basic (http / session)Monday, 4 October 2010
  26. 26. Basic AuthenticationMonday, 4 October 2010
  27. 27. Basic Authentication Username PasswordMonday, 4 October 2010
  28. 28. Basic Authentication Username Password 5f4dcc3b5aa765d6 1d8327deb882cf99Monday, 4 October 2010
  29. 29. Basic Authentication Username Password 5f4dcc3b5aa765d6 1d8327deb882cf99Monday, 4 October 2010
  30. 30. OAuth Open Standard Greater Control User SafetyMonday, 4 October 2010
  31. 31. ResponsesMonday, 4 October 2010
  32. 32. Responses XML JSON .plistMonday, 4 October 2010
  33. 33. Responses Objects XML JSON .plistMonday, 4 October 2010
  34. 34. XML • PHP DomDocument • PEAR Library for exporting straight from MySQLMonday, 4 October 2010
  35. 35. JSONMonday, 4 October 2010
  36. 36. JSON $arr =  array (a=>1,b=>2,c=>3,d=>4,e=>5);Monday, 4 October 2010
  37. 37. JSON $arr =  array (a=>1,b=>2,c=>3,d=>4,e=>5); echo json_encode($arr);Monday, 4 October 2010
  38. 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. 39. UGC Images Encoding.com Audio / FFMpeg Video Vzaar.comMonday, 4 October 2010
  40. 40. Media Links • Link in a logical way • Eg: http://apisrock.com/64x64/23456.jpgMonday, 4 October 2010
  41. 41. Location Aware Location based searching can be a bitchMonday, 4 October 2010
  42. 42. DocumentationMonday, 4 October 2010
  43. 43. Documentation • Do itMonday, 4 October 2010
  44. 44. Documentation • Do it • Even if it’s not public facing- do it!Monday, 4 October 2010
  45. 45. Hosting • Build in PHP / MySQL • Deployable on Amazon Web ServicesMonday, 4 October 2010
  46. 46. Some Good Examples • Last.fm • Twitter • FoursquareMonday, 4 October 2010
  47. 47. Any questions? • Good.Monday, 4 October 2010
  48. 48. Thanks Ben Collier Jason Fry me@bencollier.net jason@jasonfry.co.uk @ben_c @fry15Monday, 4 October 2010
  49. 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 - NASAMonday, 4 October 2010

×