Transcript
Page 1: Web APIs: The future of software

APIs: The future of the Web

Reuven M. Lerner • [email protected] February 27th, 2014

Page 2: Web APIs: The future of software

Web APIs: The future of software

Reuven M. Lerner • [email protected] February 27th, 2014

Page 3: Web APIs: The future of software

In the Beginning, There were Ones and Zeroes.

Page 4: Web APIs: The future of software

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.

Page 5: Web APIs: The future of software

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

Page 6: Web APIs: The future of software
Page 7: Web APIs: The future of software

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!

Page 8: Web APIs: The future of software
Page 9: Web APIs: The future of software

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

Page 10: Web APIs: The future of software
Page 11: Web APIs: The future of software

Programmer virtues

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

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

Page 12: Web APIs: The future of software

DRY

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

• Don't repeat yourself!

• Don't repeat yourself!

Page 13: Web APIs: The future of software

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.

Page 14: Web APIs: The future of software

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?

Page 15: Web APIs: The future of software

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

Page 16: Web APIs: The future of software

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.

Page 17: Web APIs: The future of software

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.

Page 18: Web APIs: The future of software
Page 19: Web APIs: The future of software

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

Page 20: Web APIs: The future of software

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

Page 21: Web APIs: The future of software

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.

Page 22: Web APIs: The future of software

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?

Page 23: Web APIs: The future of software

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.

Page 24: Web APIs: The future of software

XML-RPC• Dave Winer suggested that we could use a

combination of XML and HTTP for RPC!

• Works across the Internet

• Works across programming languages

• Used libraries (XML, HTTP) that already existed

• Set up a client or server in minutes!

• But is this really RPC? Actually, yes!

Page 25: Web APIs: The future of software

SOAP

• Simple Object Access Protocol

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

• Realistically: Massive overhead and complexity

Page 26: Web APIs: The future of software

"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

Page 27: Web APIs: The future of software

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?

Page 28: Web APIs: The future of software
Page 29: Web APIs: The future of software

JSON• JavaScript is everywhere!

• And JavaScript syntax is easy to understand

• So Douglas Crockford created "JSON" — JavaScript Object Notation — which makes XML-RPC look clunky and fat by comparison

• A huge number of programming languages support JSON

Page 30: Web APIs: The future of software

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

Page 31: Web APIs: The future of software
Page 32: Web APIs: The future of software

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!

Page 33: Web APIs: The future of software

If an OS is a collection of APIs you can call, then the Internet is becoming a

massively distributed OS!

Page 34: Web APIs: The future of software

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!

Page 35: Web APIs: The future of software

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

Page 36: Web APIs: The future of software

Example: Payment• It used to be difficult to deal with payment and e-

commerce — 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!

Page 37: Web APIs: The future of software

Example: Authentication• Why store usernames and passwords?

• People don't trust you

• Users need to remember another password

• You're vulnerable

• Solution: Let people log in via Facebook, LinkedIn, Google, etc.

Page 38: Web APIs: The future of software
Page 39: Web APIs: The future of software

Example: New York Times

Page 40: Web APIs: The future of software

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

Page 41: Web APIs: The future of software

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!

Page 42: Web APIs: The future of software

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!

Page 43: Web APIs: The future of software

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…

Page 44: Web APIs: The future of software

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)

Page 45: Web APIs: The future of software

Geocoding IP address

def geocoder_decode(ip_address)

Geocoder.search(ip_address).location rescue nil

end

Page 46: Web APIs: The future of software

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!

Page 47: Web APIs: The future of software

Storage

• Dropbox and Google Drive offer APIs!

• Store and retrieve Dropbox documents from within your program

• Use Dropbox for storage, and it automatically replicates!

Page 48: Web APIs: The future of software

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.)

Page 49: Web APIs: The future of software

Twitter

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

• (You can also read and search through tweets)

Page 50: Web APIs: The future of software

Using the API

def tweet_person

Twitter.update("Welcome, #{fullname}, to the #NetLogo Modeling Commons, our #{ActiveSupport::Inflector::ordinalize(Person.count)} user!")

end

Page 51: Web APIs: The future of software
Page 52: Web APIs: The future of software

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

Page 53: Web APIs: The future of software

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.

Page 54: Web APIs: The future of software

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!

Page 55: Web APIs: The future of software

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!

Page 56: Web APIs: The future of software
Page 57: Web APIs: The future of software

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

Page 58: Web APIs: The future of software

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!)

Page 59: Web APIs: The future of software

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

Page 60: Web APIs: The future of software
Page 61: Web APIs: The future of software

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!

Page 62: Web APIs: The future of software

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

Page 63: Web APIs: The future of software

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!

Page 64: Web APIs: The future of software

APIs on the server

• Consume:

• Logging, payment, analytics, authentication

• Offer:

• Authentication, read/write your unique data, aggregation, analytics

Page 65: Web APIs: The future of software

Make a fortune!

• The path to startup success:

1. Come up with an idea

2. ???

3. Profit!

Page 66: Web APIs: The future of software

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!

Page 67: Web APIs: The future of software

$

Page 68: Web APIs: The future of software

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!

Page 69: Web APIs: The future of software

Thanks! Any questions?

• You can always 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


Top Related