APIs:
The future of the Web
Reuven M. Lerner • reuven@lerner.co.il
February 27th, 2014
Web APIs:
The future of software
Reuven M. Lerner • reuven@lerner.co.il
February 27th, 2014
In the Beginning,
There were Ones and Zeroes.
Software
•

Software is the magical collection of instructions
that control a computer

•

At the end of the day, we know that there are ones
and zeroes in there.

•

No matter what language you use, the programs
you write are turned into ones and zeroes when
they are executed.
Abstraction
•

So, why not just use ones and zeroes?

•

Abstraction: One of the most important concepts in
computer science!

•

Abstraction lets you think big thoughts, not
worrying about the underlying infrastructure or
implementation
High level
•

The greatest abstractions happen in "high-level"
languages, such as Python, Ruby, JavaScript, and
Lisp
•

In low-level languages, I work hard to suit the
computer.

•

But in high-level languages, the computer works
hard to suit me, by black-boxing the details!
Repetition
•

No matter what language you use, you'll eventually
find yourself repeating code.

•

How can you deal with this problem?

•

Put the code in a common place, and then use it
again and again.

•

Write it once, and then use it — ignoring the
implementation
Programmer virtues
•

"The three virtues of a programmer: laziness,
impatience, and hubris" — Larry Wall

•

Laziness: Write it once, and then reuse it many
times!
DRY
•

This leads directly to the idea of DRY — write code
only once.

•

Don't repeat yourself!

•

Don't repeat yourself!
Libraries of code
•

Writing libraries of code, which can then be used
by many different programs, is an extremely
common programming task.

•

With a library, we can concentrate on the most
important things to our business, rather than focus
on infrastructure.
API
•

"Application Programming Interface"

•

What is the interface to a library of code?
•

Function/method names

•

Effects (what each function does)

•

Parameters expected by each function

•

Return value(s) from each function

•

What happens if there was an error?
Modern operating systems
•

What is an operating system? A bunch of libraries
that abstract away the hardware and many other
aspects of computers:
•

Networking

•

Printing

•

Running multiple programs

•

Drawing to the screen
Operating systems
•

In other words, an operating system is just a
collection of APIs!

•

You can write your own printing system, but why
bother? Just use the printing API that the operating
system provides.
From Wikipedia
•

Win32 (Windows)
•

•

The Windows API, informally WinAPI, is Microsoft's
core set of application programming interfaces
(APIs) available in the Microsoft Windows operating
systems.

Cocoa (Mac OS X)
•

Cocoa is Apple's native object-oriented application
programming interface (API) for the OS X operating
system.
RPC
•

"Remote procedure call"

•

Don't invoke a library on the local computer —
rather, invoke it on another computer!

•

Abstraction #1: The software library does some
task for me

•

Abstraction #2: I don't have to know how that things
are executing remotely
What is the Web?
•

URLs — what I want, where it's located, and how I
get there

•

HTTP — a great way to get there

•

HTML — a type of content
The entire Web, explained

•

A browser sends an HTTP request to a server.

•

The server sends a response (perhaps content,
perhaps an error message, perhaps a redirect),
and hangs up.
What if machines browsed,
and not humans?
•

The Web was designed for people.

•

But you know, the combination of URLs, HTTP, and
HTML could be used by computers, too.

•

And then you wouldn't need to have a "browser"
sending a request. It could be any program, right?
XML
•

"Extensible markup language"

•

Not a markup language, but rather a way to define
new markup languages!

•

Now computers can send requests and get results
not in human-centric HTML, but in machine-centric
XML.
XML-RPC
•

Dave Winer suggested that we could use a
combination of XML and HTTP for RPC!
•
•

Works across programming languages

•

Used libraries (XML, HTTP) that already existed

•
•

Works across the Internet

Set up a client or server in minutes!

But is this really RPC? Actually, yes!
SOAP
•

Simple Object Access Protocol

•

Officially: A more modern, well-defined version of
XML-RPC

•

Realistically: Massive overhead and complexity
"Web Services"
•

Both XML-RPC and SOAP are protocols that let you
advertise Web services

•

In other words: APIs against which we can make
calls from anywhere on the Internet!

•

There's a whole alphabet soup of standards that
were written to address this problem.

•

But today, APIs are often cleaner and leaner than
this, implemented in different ways
REST
•

Representational State Transfer (Roy Fielding)

•

URLs should be nouns, and different HTTP actions
should describe the actions on those nouns

•

Not a lot of documentation is needed, because
REST standardizes how things look on the outside

•

Wait, how does it look on the inside? What does
the implementation look like?
JSON
•

JavaScript is everywhere!

•

And JavaScript syntax is easy to understand

•

So Douglas Crockford created "JSON" —
JavaScript Object Notation — which makes XMLRPC look clunky and fat by comparison

•

A huge number of programming languages
support JSON
REST + JSON
•

Modern APIs are thus standardized via REST, and
exchange data using JSON

•

Many frameworks, such as Ruby on Rails, make it
trivially easy to create RESTful JSON APIs
Um. OK.
•

Web APIs let programs talk to other programs.

•

And? Why should I care? And how is this the
future of software?

•

Two reasons:
•

All software is moving online, and

•

The entire Internet is becoming our OS!
If an OS is a collection of APIs you can
call, then the Internet is becoming a
massively distributed OS!
In other words
•

Build the parts of your application that are special
and specific for you.

•

The rest of your application should leverage APIs
on the Web

•

And by the way, your application can offer APIs as
well, leading to a complex web of API calls!
Example: FedEx
•

One of the first companies to offer an API

•

(Yes, beyond the Web site!)

•

Benefit to your company: Create custom software
that handles all of your package needs, with the
appropriate permissions and reporting

•

Benefit to FedEx: Lock-in, customer satisfaction
Example: Payment
•

It used to be difficult to deal with payment and ecommerce — because you implemented it yourself

•

But now we have APIs that make it easier to deal
with. PayPal, Strip, Dwolla, Amazon, PayByGroup.

•

How can we simplify the API? Simple: Offer a
library that wraps up those APIs.

•

Charging credit cards becomes a one-line task!
Example: Authentication
•

Why store usernames and passwords?
•
•

Users need to remember another password

•
•

People don't trust you

You're vulnerable

Solution: Let people log in via Facebook, LinkedIn,
Google, etc.
Example: New York Times
What does this mean?
•

The New York Times is not only a source for news.

•

It's now a source for data that people can use to
inform others.

•

It becomes a platform on which you can create
new content, and do meta-reporting
Weather APIs
•

wunderground.com offers APIs to current weather
data

•

Get weather data, and integrate it into your app

•

Location-aware apps on your phone can use this to
show weather wherever you are!
Amazon Web Services
•

Everything is available via an API!

•

Start new servers, shut down existing servers, and
monitor servers — all via APIs

•

Your application can thus spin up (and spin down)
entire servers whenever it needs, using nothing
more than URLs and JSON!
Amazon?!?
•

Yes, they make billions off of their cloud servers

•

You can manage those servers via various APIs

•

Want to manage buying, selling, and management
of products on Amazon? Sure, there are APIs for
those, too…
Geocoding
•

Have a street address, and want to know its
longitude and latitude?

•

Have an IP address, and want to know its country?

•

There are APIs for this, generally from mapping
companies (e.g., Google, Bing, MapQuest)
Geocoding IP address
def geocoder_decode(ip_address)
Geocoder.search(ip_address).location rescue nil
end
A/B Testing
•

optimize.ly lets you do A/B ("split") testing on your
Web site by including a snippet of JavaScript

•

How does it work? By accessing Optimizely's API

•

How can you modify its behavior? By accessing
Optimizely's API from your own program!
Storage
•

Dropbox and Google Drive offer APIs!

•

Store and retrieve Dropbox documents from within
your program

•

Use Dropbox for storage, and it automatically
replicates!
Facebook
•

Get access to a user's personal information —
name, address, and interests

•

You also get information about the person's friends!

•

This is potentially a huge privacy issue! So users
need to agree to add Facebook API applications,
and specifically see what capabilities apps want

•

(The same is true for LinkedIn, of course.)
Twitter

•

Twitter has long offered an API, allowing anyone to
tweet from within a program

•

(You can also read and search through tweets)
Using the API
def tweet_person
Twitter.update("Welcome, #{fullname}, to the #NetLogo Modeling
Commons, our #{ActiveSupport::Inflector::ordinalize(Person.count)}
user!")
end
SOA
•

Service-Oriented Architecture

•

Instead of a big Web application, write many small
ones that talk to each other via APIs!

•

Each service can then be created, updated, and
maintained by different teams. Or companies. Or
individuals.

•

Easier to create, maintain, scale, and understand
SaaS APIs
•

SaaS — software as a service

•

Applications that run on a server somewhere; they
may have a browser-side, as well.

•

A growing number of SaaS companies offer APIs.
This turns the application into something beyond
what you use it for in your browser.
Example API: Harvest
•

"Harvest," time-tracking and invoicing software, has
an API

•

The time-tracking API lets you keep track of your
time. Build a new widget or app that starts and
stops your clock, for example.

•

The extended API lets you edit your clients,
projects, and tasks!
Example API: Job seeking
•

Looking to hire people? You can use an API to post
jobs (on monster.com, linkedin.com, and
elsewhere)

•

Looking for work? You can search via an API!

•

Trying to match jobs and people? You can use
these APIs, and build a company on top of them!
Example API: Search
•

Run searches against your favorite search engine
•

•

(Or run searches against multiple search
engines, and compare the results!)

All search engines provide APIs that let you build
on top of what they offer
ProgrammableWeb.com
•

Not sure what's out there?

•

ProgrammableWeb.com lists as many APIs as it
can, categorized by topic, protocol and data
format.

•

Don't reinvent the wheel — find one that has
already been rolling for a while, and integrate it!

•

(Let someone else do the hard work of
implementing things. Laziness wins again!)
Connecting
•

IFTTT ("If this, then that")

•

It's an connector for APIs!

•

You can say, "When I'm tagged in a photo on
Facebook, post a note to my blog."

•

Once a company is part of the IFTTT family, you
can connect APIs for added
Mobile apps
•

Mobile apps all use APIs!

•

They usually talk to Web sites via XML or JSON

•

In other words, a mobile app has two parts
•
•

•

Client (running on the device)
Server (offering a JSON API)

Support iOS and Android? Two clients, one API!
Single-page apps
•

As browsers get smarter, more of the app is being
pushed onto the client, running in JavaScript

•

So instead of each click being a new HTTP
request, you can create a whole application in the
browser that occasionally syncs with a server

•

How does it sync? APIs, of course!

•

Google Docs work just like this
Even the browser…
•

How do programs talk to the browser? Via APIs!

•

DOM — API for us to read and update a Web page

•

Call APIs from the browser, to talk to lots of servers

•

e.g., Disqus, Facebook, LiveFyre — add
discussion to any page!
APIs on the server
•

Consume:
•

•

Logging, payment, analytics, authentication

Offer:
•

Authentication, read/write your unique data,
aggregation, analytics
Make a fortune!
•

The path to startup success:

1. Come up with an idea
2. ???
3. Profit!
What's stage 2?
•

The path to startup success:

1. Come up with an idea
2. Offer an API to information or analysis that no one
else can offer
3. Profit!
$
Opportunities in your work?
•

An API doesn't have to be big or complex

•

It can often solve simple problems — saving you
money and making you more efficient

•

Don't e-mail Excel files to one another. Rather,
create an API on a local server!
Thanks!
Any questions?
•

You can always find me at:
•

reuven@lerner.co.il

•

http://www.lerner.co.il/
•

Get my newsletter, with articles and insights like this!

•

054-496-8405

•

“reuvenlerner” on Skype

•

@reuvenmlerner on Twitter

Web APIs: The future of software

  • 1.
    APIs: The future ofthe Web Reuven M. Lerner • [email protected] February 27th, 2014
  • 2.
    Web APIs: The futureof software Reuven M. Lerner • [email protected] February 27th, 2014
  • 3.
    In the Beginning, Therewere Ones and Zeroes.
  • 4.
    Software • Software is themagical collection of instructions that control a computer • At the end of the day, we know that there are ones and zeroes in there. • No matter what language you use, the programs you write are turned into ones and zeroes when they are executed.
  • 5.
    Abstraction • So, why notjust use ones and zeroes? • Abstraction: One of the most important concepts in computer science! • Abstraction lets you think big thoughts, not worrying about the underlying infrastructure or implementation
  • 7.
    High level • The greatestabstractions happen in "high-level" languages, such as Python, Ruby, JavaScript, and Lisp • In low-level languages, I work hard to suit the computer. • But in high-level languages, the computer works hard to suit me, by black-boxing the details!
  • 9.
    Repetition • No matter whatlanguage you use, you'll eventually find yourself repeating code. • How can you deal with this problem? • Put the code in a common place, and then use it again and again. • Write it once, and then use it — ignoring the implementation
  • 11.
    Programmer virtues • "The threevirtues of a programmer: laziness, impatience, and hubris" — Larry Wall • Laziness: Write it once, and then reuse it many times!
  • 12.
    DRY • This leads directlyto the idea of DRY — write code only once. • Don't repeat yourself! • Don't repeat yourself!
  • 13.
    Libraries of code • Writinglibraries of code, which can then be used by many different programs, is an extremely common programming task. • With a library, we can concentrate on the most important things to our business, rather than focus on infrastructure.
  • 14.
    API • "Application Programming Interface" • Whatis the interface to a library of code? • Function/method names • Effects (what each function does) • Parameters expected by each function • Return value(s) from each function • What happens if there was an error?
  • 15.
    Modern operating systems • Whatis an operating system? A bunch of libraries that abstract away the hardware and many other aspects of computers: • Networking • Printing • Running multiple programs • Drawing to the screen
  • 16.
    Operating systems • In otherwords, an operating system is just a collection of APIs! • You can write your own printing system, but why bother? Just use the printing API that the operating system provides.
  • 17.
    From Wikipedia • Win32 (Windows) • • TheWindows API, informally WinAPI, is Microsoft's core set of application programming interfaces (APIs) available in the Microsoft Windows operating systems. Cocoa (Mac OS X) • Cocoa is Apple's native object-oriented application programming interface (API) for the OS X operating system.
  • 19.
    RPC • "Remote procedure call" • Don'tinvoke a library on the local computer — rather, invoke it on another computer! • Abstraction #1: The software library does some task for me • Abstraction #2: I don't have to know how that things are executing remotely
  • 20.
    What is theWeb? • URLs — what I want, where it's located, and how I get there • HTTP — a great way to get there • HTML — a type of content
  • 21.
    The entire Web,explained • A browser sends an HTTP request to a server. • The server sends a response (perhaps content, perhaps an error message, perhaps a redirect), and hangs up.
  • 22.
    What if machinesbrowsed, and not humans? • The Web was designed for people. • But you know, the combination of URLs, HTTP, and HTML could be used by computers, too. • And then you wouldn't need to have a "browser" sending a request. It could be any program, right?
  • 23.
    XML • "Extensible markup language" • Nota markup language, but rather a way to define new markup languages! • Now computers can send requests and get results not in human-centric HTML, but in machine-centric XML.
  • 24.
    XML-RPC • Dave Winer suggestedthat we could use a combination of XML and HTTP for RPC! • • Works across programming languages • Used libraries (XML, HTTP) that already existed • • Works across the Internet Set up a client or server in minutes! But is this really RPC? Actually, yes!
  • 25.
    SOAP • Simple Object AccessProtocol • Officially: A more modern, well-defined version of XML-RPC • Realistically: Massive overhead and complexity
  • 26.
    "Web Services" • Both XML-RPCand SOAP are protocols that let you advertise Web services • In other words: APIs against which we can make calls from anywhere on the Internet! • There's a whole alphabet soup of standards that were written to address this problem. • But today, APIs are often cleaner and leaner than this, implemented in different ways
  • 27.
    REST • Representational State Transfer(Roy Fielding) • URLs should be nouns, and different HTTP actions should describe the actions on those nouns • Not a lot of documentation is needed, because REST standardizes how things look on the outside • Wait, how does it look on the inside? What does the implementation look like?
  • 29.
    JSON • JavaScript is everywhere! • AndJavaScript syntax is easy to understand • So Douglas Crockford created "JSON" — JavaScript Object Notation — which makes XMLRPC look clunky and fat by comparison • A huge number of programming languages support JSON
  • 30.
    REST + JSON • ModernAPIs are thus standardized via REST, and exchange data using JSON • Many frameworks, such as Ruby on Rails, make it trivially easy to create RESTful JSON APIs
  • 32.
    Um. OK. • Web APIslet programs talk to other programs. • And? Why should I care? And how is this the future of software? • Two reasons: • All software is moving online, and • The entire Internet is becoming our OS!
  • 33.
    If an OSis a collection of APIs you can call, then the Internet is becoming a massively distributed OS!
  • 34.
    In other words • Buildthe parts of your application that are special and specific for you. • The rest of your application should leverage APIs on the Web • And by the way, your application can offer APIs as well, leading to a complex web of API calls!
  • 35.
    Example: FedEx • One ofthe first companies to offer an API • (Yes, beyond the Web site!) • Benefit to your company: Create custom software that handles all of your package needs, with the appropriate permissions and reporting • Benefit to FedEx: Lock-in, customer satisfaction
  • 36.
    Example: Payment • It usedto be difficult to deal with payment and ecommerce — because you implemented it yourself • But now we have APIs that make it easier to deal with. PayPal, Strip, Dwolla, Amazon, PayByGroup. • How can we simplify the API? Simple: Offer a library that wraps up those APIs. • Charging credit cards becomes a one-line task!
  • 37.
    Example: Authentication • Why storeusernames and passwords? • • Users need to remember another password • • People don't trust you You're vulnerable Solution: Let people log in via Facebook, LinkedIn, Google, etc.
  • 39.
  • 40.
    What does thismean? • The New York Times is not only a source for news. • It's now a source for data that people can use to inform others. • It becomes a platform on which you can create new content, and do meta-reporting
  • 41.
    Weather APIs • wunderground.com offersAPIs to current weather data • Get weather data, and integrate it into your app • Location-aware apps on your phone can use this to show weather wherever you are!
  • 42.
    Amazon Web Services • Everythingis available via an API! • Start new servers, shut down existing servers, and monitor servers — all via APIs • Your application can thus spin up (and spin down) entire servers whenever it needs, using nothing more than URLs and JSON!
  • 43.
    Amazon?!? • Yes, they makebillions off of their cloud servers • You can manage those servers via various APIs • Want to manage buying, selling, and management of products on Amazon? Sure, there are APIs for those, too…
  • 44.
    Geocoding • Have a streetaddress, and want to know its longitude and latitude? • Have an IP address, and want to know its country? • There are APIs for this, generally from mapping companies (e.g., Google, Bing, MapQuest)
  • 45.
    Geocoding IP address defgeocoder_decode(ip_address) Geocoder.search(ip_address).location rescue nil end
  • 46.
    A/B Testing • optimize.ly letsyou do A/B ("split") testing on your Web site by including a snippet of JavaScript • How does it work? By accessing Optimizely's API • How can you modify its behavior? By accessing Optimizely's API from your own program!
  • 47.
    Storage • Dropbox and GoogleDrive offer APIs! • Store and retrieve Dropbox documents from within your program • Use Dropbox for storage, and it automatically replicates!
  • 48.
    Facebook • Get access toa user's personal information — name, address, and interests • You also get information about the person's friends! • This is potentially a huge privacy issue! So users need to agree to add Facebook API applications, and specifically see what capabilities apps want • (The same is true for LinkedIn, of course.)
  • 49.
    Twitter • Twitter has longoffered an API, allowing anyone to tweet from within a program • (You can also read and search through tweets)
  • 50.
    Using the API deftweet_person Twitter.update("Welcome, #{fullname}, to the #NetLogo Modeling Commons, our #{ActiveSupport::Inflector::ordinalize(Person.count)} user!") end
  • 52.
    SOA • Service-Oriented Architecture • Instead ofa big Web application, write many small ones that talk to each other via APIs! • Each service can then be created, updated, and maintained by different teams. Or companies. Or individuals. • Easier to create, maintain, scale, and understand
  • 53.
    SaaS APIs • SaaS —software as a service • Applications that run on a server somewhere; they may have a browser-side, as well. • A growing number of SaaS companies offer APIs. This turns the application into something beyond what you use it for in your browser.
  • 54.
    Example API: Harvest • "Harvest,"time-tracking and invoicing software, has an API • The time-tracking API lets you keep track of your time. Build a new widget or app that starts and stops your clock, for example. • The extended API lets you edit your clients, projects, and tasks!
  • 55.
    Example API: Jobseeking • Looking to hire people? You can use an API to post jobs (on monster.com, linkedin.com, and elsewhere) • Looking for work? You can search via an API! • Trying to match jobs and people? You can use these APIs, and build a company on top of them!
  • 57.
    Example API: Search • Runsearches against your favorite search engine • • (Or run searches against multiple search engines, and compare the results!) All search engines provide APIs that let you build on top of what they offer
  • 58.
    ProgrammableWeb.com • Not sure what'sout there? • ProgrammableWeb.com lists as many APIs as it can, categorized by topic, protocol and data format. • Don't reinvent the wheel — find one that has already been rolling for a while, and integrate it! • (Let someone else do the hard work of implementing things. Laziness wins again!)
  • 59.
    Connecting • IFTTT ("If this,then that") • It's an connector for APIs! • You can say, "When I'm tagged in a photo on Facebook, post a note to my blog." • Once a company is part of the IFTTT family, you can connect APIs for added
  • 61.
    Mobile apps • Mobile appsall use APIs! • They usually talk to Web sites via XML or JSON • In other words, a mobile app has two parts • • • Client (running on the device) Server (offering a JSON API) Support iOS and Android? Two clients, one API!
  • 62.
    Single-page apps • As browsersget smarter, more of the app is being pushed onto the client, running in JavaScript • So instead of each click being a new HTTP request, you can create a whole application in the browser that occasionally syncs with a server • How does it sync? APIs, of course! • Google Docs work just like this
  • 63.
    Even the browser… • Howdo programs talk to the browser? Via APIs! • DOM — API for us to read and update a Web page • Call APIs from the browser, to talk to lots of servers • e.g., Disqus, Facebook, LiveFyre — add discussion to any page!
  • 64.
    APIs on theserver • Consume: • • Logging, payment, analytics, authentication Offer: • Authentication, read/write your unique data, aggregation, analytics
  • 65.
    Make a fortune! • Thepath to startup success: 1. Come up with an idea 2. ??? 3. Profit!
  • 66.
    What's stage 2? • Thepath to startup success: 1. Come up with an idea 2. Offer an API to information or analysis that no one else can offer 3. Profit!
  • 67.
  • 68.
    Opportunities in yourwork? • An API doesn't have to be big or complex • It can often solve simple problems — saving you money and making you more efficient • Don't e-mail Excel files to one another. Rather, create an API on a local server!
  • 69.
    Thanks! Any questions? • You canalways find me at: • [email protected] • http://www.lerner.co.il/ • Get my newsletter, with articles and insights like this! • 054-496-8405 • “reuvenlerner” on Skype • @reuvenmlerner on Twitter