APIs - Application Programming Interfaces


Published on

A brief overview of software APIs. Visit delphicsage.com for the blog post as well.

Published in: Education, Technology
1 Comment
1 Like
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  •    As a developer, you don't have to care how the data is stored, and in most cases, how the functionality is implemented.
  • On the web so you can access it anywhere. Put your images on flickr.com instead of bobsimages.com. Hosting is expensive. All your images on flickr, all videos on youtube.  Hosting is expensive. Don't have to write a program to plot every point and address on the planet, use geocoder.us.
  • Uses HTTP verbs (GET, POST, PUT, DELETE) PUT updates a resource (message, comment, to-do item), POST creates.  Uses HTTP status codes to determine success (200 OK, 201 CREATED)
  • Flickr API It can send responses in the following formats - XML, XML-RPC, SOAP, JSON, PHP (a serialized format, which can be deserialized easily in PHP simply by calling  unserialize ).  There are many libraries written, in .NET, Java, C, etc, that implement the API.
  • wsdl "C:WSDL090821.wsdl" /out:c:NewWSDL_712.cs
  • APIs JSR 179 Blackberries run Java, JSR 179 is the location API for Java enabled devices Flickr API Geocoder.us API TinyURL API  (URL based, returns a string) Twitter API EXIF data API How do I make it? Implement location tracker for blackberry phone to plot location every minute, which requires that clock on the blackberry and the camera are synched. Take pictures! Import pictures to computer, import GPS log from blackberry to computer Write application that will go through each image, find a log entry in the GPS tracker for the time it was taken (or interpolate location), use EXIF API to write into the file where the photo was taken Upload photo to flickr via API, grouping photos together by location and date into Albums. Send Flickr album url to TinyURL API Make a tweet through Twitter API that contains album name and tiny url.
  • A phone app that takes text like "Pick up milk at 7" and is always running in the background.  Most phones provide a calendar, but they are usually multi-steps, like finding the date and time, clicking create event, adding the text, setting some parameters like duration, etc.  This would be much simpler. Send create calendar event request to Google Calendar API Get list of events every hour for the next hour http://www.google.com/calendar/feeds/default/private/full?start-min=2009-10-14T12:30:00&start-max=2009-10-14T13:30:00 OR use Google Sync which does this for you. Buzz or beep to remind the user to look at the phone when a new item comes up. (Handled already if Google Sync is used)
  • APIs - Application Programming Interfaces

    1. 1. APIs What they are and why we use them
    2. 2. API Defined <ul><ul><li>Application Programming Interface </li></ul></ul><ul><ul><li>A way to use data or functionality written by a third party </li></ul></ul><ul><ul><li>Data / Functionality Abstraction </li></ul></ul><ul><ul><li>Often platform agnostic, nowadays very often web related / enabled </li></ul></ul><ul><ul><li>Different from </li></ul></ul><ul><ul><ul><li>Software Library </li></ul></ul></ul><ul><ul><ul><li>Software Development Kit (SDK) </li></ul></ul></ul>
    3. 3. The I is for Interface <ul><li>The Interface abstracts data / functionality. </li></ul><ul><li>The Interface can take many different forms </li></ul><ul><ul><li>Libraries written for specific platforms </li></ul></ul><ul><ul><ul><li>Example: DirectX for Windows, C++, C# </li></ul></ul></ul><ul><ul><ul><li>Example: Facebook has a PHP Library </li></ul></ul></ul><ul><ul><li>Web interface </li></ul></ul><ul><ul><ul><li>A whole 'nother beast </li></ul></ul></ul><ul><ul><ul><li>Data Formats: XML, YAML, JSON, SOAP, string, etc. </li></ul></ul></ul><ul><ul><ul><li>Transmission Formats: HTTP, HTTPS </li></ul></ul></ul><ul><ul><ul><li>Platform Formats:  REST, Web Services, XML-RPC </li></ul></ul></ul>
    4. 4. Benefits of APIs <ul><li>Web APIs </li></ul><ul><ul><li>On the Web! </li></ul></ul><ul><ul><li>Put your data on highly trafficked sites </li></ul></ul><ul><ul><li>Access and store data in a central location </li></ul></ul><ul><ul><li>Not reinvent the wheel </li></ul></ul><ul><ul><li>Extend functionality </li></ul></ul><ul><li>Non-Web APIs </li></ul><ul><ul><li>Gain access to application functionality (Office) </li></ul></ul><ul><ul><li>Gain access to hardware </li></ul></ul><ul><ul><li>Not many apps provide an API nowadays, but more of a plugin system (Firefox, Google Desktop, Apple Widgets). </li></ul></ul><ul><ul><li>Control Robots. </li></ul></ul>
    5. 5. Problems!! <ul><ul><li>APIs change </li></ul></ul><ul><ul><ul><li>Salesforce.com guarantees 3 years of support </li></ul></ul></ul><ul><ul><li>Complex </li></ul></ul><ul><ul><ul><li>Google APIs are very complex </li></ul></ul></ul><ul><ul><ul><li>THINK API is easy to implement, very difficult to use </li></ul></ul></ul><ul><ul><li>Documentation </li></ul></ul><ul><ul><ul><li>THINK API </li></ul></ul></ul><ul><ul><li>Authentication </li></ul></ul><ul><ul><ul><li>Most APIs require a user or API key or both </li></ul></ul></ul><ul><ul><li>Bugs </li></ul></ul><ul><ul><ul><li>All software has bugs, APIs are no different </li></ul></ul></ul><ul><ul><li>Error Messages </li></ul></ul><ul><ul><ul><li>Some error messages are no help </li></ul></ul></ul><ul><ul><ul><li>HTTP Status codes in REST can mean different things </li></ul></ul></ul>
    6. 6. Example Uses of APIs <ul><ul><li>GeoCoder.us uses the most basic of interfaces </li></ul></ul><ul><ul><ul><li>http://geocoder.us/service/csv?address=11045+Queens+Blvd,+Forest+Hills+NY+11375 </li></ul></ul></ul><ul><ul><ul><li>Returns a CSV string </li></ul></ul></ul><ul><ul><ul><ul><li>40.719546,-73.839686,11045 Queens Blvd,New York,NY,11375 </li></ul></ul></ul></ul><ul><ul><li> Basecamp uses a complex interface </li></ul></ul><ul><ul><ul><li>Data formatted as XML </li></ul></ul></ul><ul><ul><ul><li>REST based </li></ul></ul></ul><ul><ul><ul><ul><li>https://delphicsage.basecamphq.com/projects/3804405/posts/26028930.xml </li></ul></ul></ul></ul>
    7. 7. Example Uses Continued <ul><ul><li>THINK Subscription - SOAP through Web Services. </li></ul></ul><ul><ul><li>Twitter - XML or JSON through REST </li></ul></ul><ul><ul><li>Flickr - REST, XML-RPC or SOAP.  </li></ul></ul><ul><ul><li>Salesforce.com - SOAP through Web Services </li></ul></ul><ul><ul><li>Amazon - SOAP through Web Services </li></ul></ul><ul><ul><li>YouTube - REST and ATOM with extensions. </li></ul></ul>
    8. 8. What are all these protocols? <ul><li>Web Services </li></ul><ul><ul><li>WSDL (wizz-dull) </li></ul></ul><ul><ul><li>XML response data (.NET WS can return JSON too). </li></ul></ul><ul><ul><li>Pros: Generate code, development tools (Axis, .NET System.Web.Services, wsdl.exe) </li></ul></ul><ul><ul><li>Cons: Difficult to write code against if it's not generated.  Heavy weight with strict type checking and XSD validation. </li></ul></ul><ul><li>REST ( Representational State Transfer) </li></ul><ul><ul><li>  A representation of a resource is typically a document that captures the current or intended state of a resource. </li></ul></ul><ul><ul><li>Does not specify anything about the format of the data </li></ul></ul><ul><ul><li>Requests are made to URL </li></ul></ul><ul><ul><li>No definition language, no code generation in most cases </li></ul></ul><ul><ul><li>Pros: Less strict, less bulk, very straightforward, makes sense. </li></ul></ul><ul><ul><li>Cons: Less strict, all code must be written if no libraries from API provider. (Flickr provides many), some REST APIs mix important data in XML, HTTP Headers, HTTP Status codes. </li></ul></ul><ul><li>XML-RPC </li></ul><ul><ul><li>On its way out... </li></ul></ul>
    9. 9. Example Application using APIs <ul><li>Problem:  You bought a digital camera, but it does not have a geocoding attachment. You also want to group images taken in the same general location together into albums on Flickr, and send a tweet out with a tinyURL link to the album. </li></ul><ul><li>Materials You Have: </li></ul><ul><ul><li>Digital Camera </li></ul></ul><ul><ul><li>Blackberry or other GPS enabled device (GPS logger) </li></ul></ul><ul><ul><li>Internet connection </li></ul></ul><ul><li>APIs required </li></ul><ul><ul><li>???????? </li></ul></ul><ul><ul><li>Discuss </li></ul></ul><ul><li>How do I make it? </li></ul><ul><ul><li>???????? </li></ul></ul><ul><ul><li>Discuss </li></ul></ul>
    10. 10. Another Application <ul><li>Problem:  You are unorganized and forget things immediately. </li></ul><ul><li>Materials: </li></ul><ul><ul><li>Internet connection </li></ul></ul><ul><ul><li>Phone with Keyboard </li></ul></ul><ul><ul><li>Computer </li></ul></ul><ul><li>APIs required </li></ul><ul><ul><li>??????? </li></ul></ul><ul><ul><li>Discuss </li></ul></ul><ul><li>How do I make it? </li></ul><ul><ul><li>??????? </li></ul></ul><ul><ul><li>Discuss </li></ul></ul>
    11. 11. You might be an API if... <ul><ul><li>Subjective... </li></ul></ul><ul><ul><li>Many things can be considered an API, even if the author did not intend for it to be called that. </li></ul></ul><ul><ul><li>Any SDK (software development kit) is probably a collection of APIs (like iPhone, Java, .NET SDK). </li></ul></ul><ul><ul><li>You make some complex task simple.... </li></ul></ul><ul><ul><li>You make some inaccessible data accessible..... </li></ul></ul><ul><ul><li>You make accessing hardware simple (USB API, Network stack, OpenGL, OpenAL, etc).... </li></ul></ul><ul><ul><li>If you are accessing an external system without hacking, you're probably using an API. </li></ul></ul>
    12. 12. You are definitely NOT an API if... <ul><ul><li>Code is written to run on you (Platform) </li></ul></ul><ul><ul><li>You are an application. </li></ul></ul><ul><ul><li>You're hardware. </li></ul></ul><ul><ul><li>You're data. </li></ul></ul><ul><ul><li>^^^ These are all things that an API would be written for! </li></ul></ul>
    13. 13. Questions?