73
APIs for the Mobile World Michele Titolo Lead Software Engineer @ Capital One

APIs for the Mobile World

Embed Size (px)

Citation preview

Page 1: APIs for the Mobile World

APIs for the Mobile WorldMichele Titolo Lead Software Engineer @ Capital One

Page 2: APIs for the Mobile World

Why APIs for the

world?mobile

Page 3: APIs for the Mobile World

People 💖 Apps

Page 4: APIs for the Mobile World

Apps Have To Be Great 👍

Page 5: APIs for the Mobile World

Apps Are Complicated

Page 6: APIs for the Mobile World

📶🔗

🕐‼

👑

Page 7: APIs for the Mobile World

Can APIs make an app not great? Yes.

Page 8: APIs for the Mobile World

How?

Page 9: APIs for the Mobile World

Slow 💤

Page 10: APIs for the Mobile World

State 🙅

Page 11: APIs for the Mobile World

Crashes 💥

Page 12: APIs for the Mobile World

Oops something’s amiss

Page 13: APIs for the Mobile World

Slows Down Development

Page 14: APIs for the Mobile World
Page 15: APIs for the Mobile World

great📱5ways to make

experiences

Page 16: APIs for the Mobile World

Keep Things Consistent.1

Page 17: APIs for the Mobile World

Established Conventions

Page 18: APIs for the Mobile World

Don’t Return 200 With “Error”

Page 19: APIs for the Mobile World

Follow Your Own Conventions

Page 20: APIs for the Mobile World

Endpoint “id” field

/products id

/products/:id productID

/cart product_id

Page 21: APIs for the Mobile World

Document Everything.2

Page 22: APIs for the Mobile World

does notself documenting

code

exist

Page 23: APIs for the Mobile World

Ask So And So Is Not Documentation

Page 24: APIs for the Mobile World

Update Documentation

Page 25: APIs for the Mobile World

Communicate

Page 26: APIs for the Mobile World

Make Documentation Part Of The Process

Page 27: APIs for the Mobile World

Auto-Generate

Page 28: APIs for the Mobile World

Honor thy contracts.3

Page 29: APIs for the Mobile World

Documentation Is A Contract

Page 30: APIs for the Mobile World

Versioning

Page 31: APIs for the Mobile World

Unexpected Breaking Changes

Page 32: APIs for the Mobile World

http://

Page 33: APIs for the Mobile World

500s that return HTML

Page 34: APIs for the Mobile World

Insulate the client.4

Page 35: APIs for the Mobile World

SomethingWILL PROBABLY GOWRONG

Page 36: APIs for the Mobile World

Long Release Cycles

Page 37: APIs for the Mobile World

Releasing An App Doesn't Mean People Will Use It

Page 38: APIs for the Mobile World

Gateway Or Reverse Proxy

Page 39: APIs for the Mobile World

The Bigger Your Ecosystem, The More This Is Needed

Page 40: APIs for the Mobile World

Route To Different Servers

Page 41: APIs for the Mobile World

Mutate Requests And Responses

Page 42: APIs for the Mobile World

Zuul

Page 43: APIs for the Mobile World

Make an API just for mobile

.5

Page 44: APIs for the Mobile World

Backend For Frontend

Page 45: APIs for the Mobile World

Tailor APIs to Mobile Experiences

Page 46: APIs for the Mobile World

Not A New Concept

Page 47: APIs for the Mobile World

Why?

Page 48: APIs for the Mobile World

RestRepresentational State Transfer

= Data

Page 49: APIs for the Mobile World

Imagine…

Page 50: APIs for the Mobile World

The most amazing movie app in the world

Page 51: APIs for the Mobile World

Lets Add A New Feature

Page 52: APIs for the Mobile World

Show nearby movie times

Page 53: APIs for the Mobile World

# Obtain a list of moviesGET /movies

# Obtain a list of nearby theatresGET /theatres?lat=…&long=…

# Obtain the showing times for a theatreGET /theatres/1234/times

Page 54: APIs for the Mobile World

server.makeMoviesRequest { (movieList, error) in

if error {

// handle error case

} else {

// handle success case

}

}

Page 55: APIs for the Mobile World

server.makeMoviesRequest { (movieList, error) in

if error {

// handle error case

} else {

// handle success case

}

}

server.makeTheatresRequest(lat,long) { (theatreList, error) in

if error {

// handle error case

} else {

// handle success case

}

}

Page 56: APIs for the Mobile World

var moviesRequestComplete: Bool = false

var theatresRequestComplete: Bool = false

server.makeMoviesRequest { (movieList, error) in

if error {

// handle error case

} else {

moviesRequestComplete = true

// do something with the data

}

}

server.makeTheatresRequest(lat,long) { (theatreList, error) in

if error {

// handle error case

} else {

theatresRequestComplete = true

// do something with the data

}

}

Page 57: APIs for the Mobile World

func makeInitialServerCalls () {

var moviesRequestComplete: Bool = false

var theatresRequestComplete: Bool = false

server.makeMoviesRequest { (movieList, error) in

if error {

// handle error case

} else {

moviesRequestComplete = true

// do something with the data

}

}

server.makeTheatresRequest(lat,long) { (theatreList, error) in

if error {

// handle error case

} else {

theatresRequestComplete = true

// do something with the data

}

}

}

func makeTheatreTimesRequest(for: theatres) {

for theatre in theatres {

server.makeTheatreTimesRequest(theatre.id) {

if error {

// handle error case

} else {

// process movie times

}

}

}

}

Page 58: APIs for the Mobile World

func makeInitialServerCalls () {

var moviesRequestComplete: Bool = false

var theatresRequestComplete: Bool = false

server.makeMoviesRequest { (movieList, error) in

if error {

// handle error case

} else {

moviesRequestComplete = true

self.movies = movieList

}

}

server.makeTheatresRequest(lat,long) { (theatreList, error) in

if error {

// handle error case

} else {

theatresRequestComplete = true

makeTheatreTimesRequest(for: theatreList)

}

}

}

func makeTheatreTimesRequest(for: theatres) {

let closestTheatres = theatres..3 // get 3 closest theatres

for theatre in closestTheatres {

if !requestTimesForTheatreAndReturnIfAnotherRequestShouldBeMade(theatre) {

break

}

}

}

func requestTimesForTheatreAndReturnIfAnotherRequestShouldBeMade(theatre) {

server.makeTheatreTimesRequest(theatre.id) {

if error {

// handle error case

} else {

// process movie times

}

}

}

Page 59: APIs for the Mobile World

func makeInitialServerCalls () {

var moviesRequestCompletedSucessfully: Bool = false

var theatresRequestComplete: Bool = false

server.makeMoviesRequest { (movieList, error) in

if error {

// handle error case

} else {

moviesRequestCompletedSucessfully = true

self.movies = movieList

}

}

server.makeTheatresRequest(lat,long) { (theatreList, error) in

if error {

// handle error case

layoutMovies()

} else {

theatresRequestComplete = true

if moviesRequestCompletedSuccessfully {

makeTheatreTimesRequest(for: theatreList)

}

}

}

}

func makeTheatreTimesRequest(for: theatres) {

let closestTheatres = theatres..3 // get 3 closest theatres

var theatreTimesAPIsFinished: Bool = false

for theatre in closestTheatres {

if !requestTimesForTheatreAndReturnIfAnotherRequestShouldBeMade(theatre) {

theatreTimesAPIsFinished = true

break

}

}

layoutMovies()

}

func requestTimesForTheatreAndReturnIfAnotherRequestShouldBeMade(theatre) {

server.makeTheatreTimesRequest(theatre.id) {

if error {

// handle error case

} else {

// process movie times

}

}

}

🚫

🙀

💩

Page 60: APIs for the Mobile World

Multiple Client Implementations

Page 61: APIs for the Mobile World

More Bugs

Page 62: APIs for the Mobile World

Error Scenarios Times Many

Page 63: APIs for the Mobile World

Release Dependent Changes

Page 64: APIs for the Mobile World

Release Dependent Experiments

Page 65: APIs for the Mobile World

Resource Based Apis Make Creating Experiences Difficult

Page 66: APIs for the Mobile World

Solution: Apis For Mobile Experiences

Page 67: APIs for the Mobile World

Logic Has To Live Somewhere

Page 68: APIs for the Mobile World

Easier To Release And Iterate

Page 69: APIs for the Mobile World

Makes Mobile Development Easier

Page 70: APIs for the Mobile World

Great Experiences

Page 71: APIs for the Mobile World

1. Keep It Consistent 2. Document Everything 3. Honor Thy Contracts 4. Insulate The App 5. Make Something Special

In Summary

Page 72: APIs for the Mobile World

Thank You!@micheletitolo

Page 73: APIs for the Mobile World

• https://unsplash.com/search/phone?photo=0VGG7cqTwCo

• https://unsplash.com/search/phone?photo=UGX2qdjdKkw

Photo Credits