Slide 1

Slide 1 text

API STRATEGY AND PRACTICE Part II

Slide 2

Slide 2 text

APIs : A Strategy Guide

Slide 3

Slide 3 text

Key Design Principles for APIs

Slide 4

Slide 4 text

Technical Best Practices from the Tumblr Are there any technical best practices from the Tumblr API you’d like to share? ! We want our API to be easy to learn without documentation—the way we lay out our URIs, you should just be able to drop into a command live. ! We try to only slightly tweak the API. One of the big ironies of a website is that I can change it whenever I want, but an API is very brittle in that you can break your developers’ applications. Versioning is an ongoing task. ! Derek Gottfrid, Director of Product, Tumblr

Slide 5

Slide 5 text

Best Practices for API Design Differentiate Your API Make Your API Easy to Try and Use Make Your API Easy to Understand Don’t Do Anything Weird Less Is More Target a Specific Developer Segment

Slide 6

Slide 6 text

• The data is unique, more complete, or more accurate than that of your competitors • You offer better support or an easier signup process • Your API is more robust, reliable, cooler, or faster than alternatives • Your terms are more developer friendly; perhaps you offer more data traffic for free or better rates Differentiate Your API

Slide 7

Slide 7 text

If your API is one of many options, your audiences may dedicate only a few minutes to trying it. If they can’t make almost immediate progress, they’ll go elsewhere. Successful API programs remove all barriers to use. Make Your API Easy to Try and Use

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

“My advice —the simpler, the better. REST, JSON, simple and straightforward services. Don’t try to make it too complex. Focus on the core building blocks for an API. Do one thing, do it really well, and bundle it with simple documentation and code samples. These are the essentials of an API.” - Kin Lane, developer evangelist at Mimeo Make Your API Easy to Understand

Slide 10

Slide 10 text

• Stick to conventions that the developer might already know. • Think about using common conventions such as OAuth or other commonly understood security schemes. • This may not only increase adoption but also reduce your (and their) development effort. Don’t Do Anything Weird

Slide 11

Slide 11 text

Less Is More Successful APIs often start with the absolute minimum amount of functionality, and then add functions slowly over time, as feedback is collected.

Slide 12

Slide 12 text

Target a Specific Developer Segment When launching the API, it is important to have expectations about how the service will likely be used so that you can launch an API that satisfies use cases. A : “Who are your target audiences?” B : “Everybody” A : “What kinds of apps do you expect to see built?” B : “All kinds” Wrong:

Slide 13

Slide 13 text

Technical Considerations for API Design

Slide 14

Slide 14 text

REST “Representational State Transfer” developed as a PhD dissertation by Roy Fielding In essence, Fielding proposed using HTTP for inter-computer communications. Consequently, REST is based on the HTTP standard. Using the building blocks of HTTP, it divides the namespace into a set of “resources” based on unique URI patterns and uses the standard HTTP verbs -- GET, POST, PUT, and DELETE -- to map operations on top of those resources.

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

...! /getAllDogs! /locationVerify! /foodNeeded! /createRecurringDogWalk! /giveDirectOrder! /healthCheck! /getRecurringDogWalkSchedule! /getLocation! /getDog! /massDogParty! /getNewDogsSince! /getRedDogs! /getSittingDogs! /dogStateChangesSearch! /replaceSittingDogsWithRunningDogs! /saveDog! ... A puppy’s world is big.

Slide 17

Slide 17 text

...! /getAllDogs! /verifyLocation! /feedNeeded! /createRecurringWakeUp! /giveDirectOrder! /checkHealth! /getRecurringWakeUpSchedule! /getLocation! /getDog! /newDog! /getNewDogsSince! /getRedDogs! /getSittingDogs! /setDogStateTo! /replaceSittingDogsWithRunningDogs! /saveDog! ... ...! /getAllLeashedDogs! /verifyVeterinarianLocation! /feedNeededFood! /createRecurringMedication! /doDirectOwnerDiscipline! /doExpressCheckupWithVeterinarian! /getRecurringFeedingSchedule! /getHungerLevel! /getSquirrelsChasingPuppies! /newDogForOwner! /getNewDogsAtKennelSince! /getRedDogsWithoutSiblings! /getSittingDogsAtPark! /setLeashedDogStateTo! /replaceParkSittingDogsWithRunningDogs! /saveMommaDogsPuppies! ...

Slide 18

Slide 18 text

We are on a slippery slope.

Slide 19

Slide 19 text

We only need two base URLs per resource.

Slide 20

Slide 20 text

The first is for a collection.

Slide 21

Slide 21 text

/dogs

Slide 22

Slide 22 text

The second is for an element

Slide 23

Slide 23 text

/dogs/1234

Slide 24

Slide 24 text

POST GET PUT DELETE

Slide 25

Slide 25 text

CREATE READ UPDATE DELETE

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

Verbs are bad.

Slide 28

Slide 28 text

Nouns are good.

Slide 29

Slide 29 text

Plurals or singulars?

Slide 30

Slide 30 text

Foursquare GroupOn Zappos /checkins /deals /Product

Slide 31

Slide 31 text

/dogs Plurals are better.

Slide 32

Slide 32 text

Abstract or concrete naming?

Slide 33

Slide 33 text

Super High High Medium /things /animals /dogs /beagles Low

Slide 34

Slide 34 text

/dogs Concrete is better than abstract

Slide 35

Slide 35 text

What about associations?

Slide 36

Slide 36 text

GET /owners/1234/dogs POST /owners/1234/dogs

Slide 37

Slide 37 text

What about complex variations?

Slide 38

Slide 38 text

/dogs?color=red&state=running&location=park

Slide 39

Slide 39 text

Error?

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

Versioning?

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

/v1/dogs

Slide 45

Slide 45 text

- What happens to older versions? - What happens to apps developed on older versions? - Do new versions support all the functionality of the older apps, or must API customers need to update their apps to work with newer versions? - Do you have a plan for minimizing the number of times you ask developers to upgrade or change versions?

Slide 46

Slide 46 text

Pagination?

Slide 47

Slide 47 text

/dogs?limit=25&offset=50

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

/dogs.json /dogs/1234.json

Slide 50

Slide 50 text

What about non-resource-y stuff?

Slide 51

Slide 51 text

Calculate Translate Convert

Slide 52

Slide 52 text

/convert?from=IDR&to=SGD&amount=100 Use verbs not nouns

Slide 53

Slide 53 text

Searching?

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

What about the rest of the URL?

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

What about authentication?

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

OAuth 2.0 Use latest OAuth

Slide 61

Slide 61 text

Be RESTful Only 2 URLs No verbs Use nouns as plurals Concrete over abstract For JSON follow JavaScript conventions Sweep complexity behind the ‘?’ Borrow from leading APIs

Slide 62

Slide 62 text

Thank You!