apis - application programming interfaces

13
APIs What they are and why we use them

Upload: jason-connell

Post on 22-Nov-2014

3.276 views

Category:

Education


6 download

DESCRIPTION

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

TRANSCRIPT

Page 1: APIs - Application Programming Interfaces

APIsWhat they are and why we use them

Page 2: APIs - Application Programming Interfaces

API Defined• Application Programming Interface• A way to use data or functionality written by a third party• Data / Functionality Abstraction• Often platform agnostic, nowadays very often web

related / enabled• Different from

o Software Libraryo Software Development Kit (SDK)

Page 3: APIs - Application Programming Interfaces

The I is for Interface

The Interface abstracts data / functionality.

The Interface can take many different forms• Libraries written for specific platforms

o Example: DirectX for Windows, C++, C#o Example: Facebook has a PHP Library

• Web interfaceo A whole 'nother beasto Data Formats: XML, YAML, JSON, SOAP, string, etc.o Transmission Formats: HTTP, HTTPSo Platform Formats:  REST, Web Services, XML-RPC

Page 4: APIs - Application Programming Interfaces

Benefits of APIsWeb APIs• On the Web!• Put your data on highly trafficked sites• Access and store data in a central location• Not reinvent the wheel• Extend functionality

Non-Web APIs• Gain access to application functionality (Office)• Gain access to hardware• Not many apps provide an API nowadays, but more of a

plugin system (Firefox, Google Desktop, Apple Widgets).• Control Robots.

Page 5: APIs - Application Programming Interfaces

Problems!!• APIs change

o Salesforce.com guarantees 3 years of support• Complex

o Google APIs are very complexo THINK API is easy to implement, very difficult to use

• Documentationo THINK API

• Authenticationo Most APIs require a user or API key or both

• Bugso All software has bugs, APIs are no different

• Error Messageso Some error messages are no helpo HTTP Status codes in REST can mean different things

Page 6: APIs - Application Programming Interfaces

Example Uses of APIs• GeoCoder.us uses the most basic of interfaces

o http://geocoder.us/service/csv?address=11045+Queens+Blvd,+Forest+Hills+NY+11375

o Returns a CSV string 40.719546,-73.839686,11045 Queens Blvd,New York,NY,11375

• Basecamp uses a complex interfaceo Data formatted as XMLo REST based

https://delphicsage.basecamphq.com/projects/3804405/posts/26028930.xml

Page 7: APIs - Application Programming Interfaces

Example Uses Continued

• THINK Subscription - SOAP through Web Services.• Twitter - XML or JSON through REST• Flickr - REST, XML-RPC or SOAP. • Salesforce.com - SOAP through Web Services• Amazon - SOAP through Web Services• YouTube - REST and ATOM with extensions.

Page 8: APIs - Application Programming Interfaces

What are all these protocols?Web Services• WSDL (wizz-dull)• XML response data (.NET WS can return JSON too).• Pros: Generate code, development tools (Axis, .NET System.Web.Services,

wsdl.exe)• Cons: Difficult to write code against if it's not generated.  Heavy weight with

strict type checking and XSD validation.

REST (Representational State Transfer)•  A representation of a resource is typically a document that

captures the current or intended state of a resource.• Does not specify anything about the format of the data• Requests are made to URL• No definition language, no code generation in most cases• Pros: Less strict, less bulk, very straightforward, makes sense.• 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.

XML-RPC• On its way out...

Page 9: APIs - Application Programming Interfaces

Example Application using APIsProblem:  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.

Materials You Have:• Digital Camera• Blackberry or other GPS enabled device (GPS logger)• Internet connection

APIs required• ????????• Discuss

How do I make it?• ????????• Discuss

Page 10: APIs - Application Programming Interfaces

Another ApplicationProblem:  You are unorganized and forget things immediately.

Materials:• Internet connection• Phone with Keyboard• Computer

APIs required• ???????• Discuss

How do I make it?• ???????• Discuss

Page 11: APIs - Application Programming Interfaces

You might be an API if...• Subjective...• Many things can be considered an API, even if the

author did not intend for it to be called that.• Any SDK (software development kit) is probably a

collection of APIs (like iPhone, Java, .NET SDK).• You make some complex task simple....• You make some inaccessible data accessible.....• You make accessing hardware simple (USB API,

Network stack, OpenGL, OpenAL, etc)....• If you are accessing an external system without

hacking, you're probably using an API.

Page 12: APIs - Application Programming Interfaces

You are definitely NOT an API if...• Code is written to run on you (Platform)• You are an application.• You're hardware.• You're data.• ^^^ These are all things that an API would be written for!

Page 13: APIs - Application Programming Interfaces

Questions?