Slide 1

Slide 1 text

Retrofitting Control Flow

Slide 2

Slide 2 text

Retrofit

Slide 3

Slide 3 text

Control Flow

Slide 4

Slide 4 text

Library Maintainer Decisions' Trickle-Down Impact

Slide 5

Slide 5 text

Background

Slide 6

Slide 6 text

Background

Slide 7

Slide 7 text

Handling Errors v1

Slide 8

Slide 8 text

try { request.makeRequest(); // if you reach this, request succeeded! return request; } catch (RetrofitError error) { Response errorResponse = error.getResponse(); switch (error.getKind()) { case NETWORK: case HTTP: case CONVERSION: case UNEXPECTED: // deal with error }

Slide 9

Slide 9 text

• NETWORK • HTTP • CONVERSION • UNEXPECTED

Slide 10

Slide 10 text

void Boolean onMakeRequest() { List shoes = // call to get shoes return shoes.isEmpty(); }

Slide 11

Slide 11 text

void List onMakeRequest() { List myFavoriteShoes = // call to get my shoes List friendsFavoriteShoes = // call to get friend's shoes return myFavoriteShoes.addAll(friendsFavoriteShoes); }

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Handling Errors v2

Slide 14

Slide 14 text

try { response = request.makeRequest(); if (response.isSuccess()) { return request; } else { // server error? } } catch (IOException e) { // network error } catch (Exception ex) { // unexpected/parse error throw ex; }

Slide 15

Slide 15 text

V1 Success != V2 Success

Slide 16

Slide 16 text

v1 Success: • connected to the server • received a successful response • parsed the response successfully • here's your object.

Slide 17

Slide 17 text

v2 Success: • connected to the server • received a response.

Slide 18

Slide 18 text

void List onMakeRequest() { Response shoesResponse = // call to get my shoes if (!shoesResponse.isSuccess()) return error!!; Response friendsResponse = // call to get friend's shoes if (!friendResponse.isSuccess()) return error!!; // otherwise proceed. }

Slide 19

Slide 19 text

Try/Catch Blocks

Slide 20

Slide 20 text

1 method call -> 1 object returned

Slide 21

Slide 21 text

1 method call -> 1 object type || ∞ errors

Slide 22

Slide 22 text

Retrofit v2: but why?

Slide 23

Slide 23 text

\\ v1 @GET("/my/shoes") List getShoes(); \\ v2 @GET("/my/shoes") Call> getShoes();

Slide 24

Slide 24 text

Retrofit!! The Best API Glue On The Market!

Slide 25

Slide 25 text

Thanks! @niftynei