This document discusses APIs for mobile applications and provides 5 recommendations for building great mobile experiences through APIs. The recommendations are: 1) Keep API conventions consistent, 2) thoroughly document APIs, 3) maintain backwards compatibility in API versioning, 4) implement error handling and caching to insulate mobile clients from issues, and 5) design APIs specifically for mobile use cases and experiences rather than just exposing backend data. The document argues that mobile-optimized APIs can improve development speed and iteration, reduce bugs from client-specific implementations, and better support creating customized mobile experiences.
53. # Obtain a list of movies
GET /movies
# Obtain a list of nearby theatres
GET /theatres?lat=…&long=…
# Obtain the showing times for a theatre
GET /theatres/1234/times
55. 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
}
}
56. 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
}
}
57. 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
}
}
}
}
58. 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
}
}
}
59. 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
}
}
}
‼
❓
🚫
🙀
💩