Slide 1

Slide 1 text

Lessons in Building APIs from From @ImgurAPI and Beyond

Slide 2

Slide 2 text

Jasdev Singh @jasdev 4 Former iOS and API Engineer at Imgur 4 Organizer of Hack.UVA 4 Currently attending Recurse Center

Slide 3

Slide 3 text

Disclaimer: I don't know everything there is about APIs. However, I learned a lot during my time and Imgur and beyond. I hope you find something from this talk applicable !

Slide 4

Slide 4 text

Topics 4 API Planning 4 Versioning 4 Routes 4 Documentation 4 Testing 4 Favorite Tools, Safeguards 4 API Support

Slide 5

Slide 5 text

API Planning

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Greenfield Project? Use a statically-typed language. Go, Scala, Swiftsoon

Slide 8

Slide 8 text

"The best API designers are also API consumers."

Slide 9

Slide 9 text

Versioning

Slide 10

Slide 10 text

URL Versioning? Header Versioning?

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Defining Your Routes 4 Resources (nouns) 4 Mapped onto the URL 4 Actions (verbs) 4 Reflected via HTTP methods: GET, POST, PUT, DELETE, etc.

Slide 13

Slide 13 text

Example 4 GET /products - Lists all products 4 GET /products/8 - Retrieves a specific product 4 POST /products - Creates a new product 4 PUT /products/8 - Update specific product 4 DELETE /products/8 - Delete a specific product

Slide 14

Slide 14 text

Parameters 4 Avoid sticking parameters in routes. Defer to query parameters or form data. 4 e.g. GET /products/search?q=:query instead of GET / products/search/:query 4 Other examples include pagination, like page and per_page. Important to return pagination information in the response (links to the next, previous, first, and last pages of a given collection).

Slide 15

Slide 15 text

Documentation "Documentation is the UX of your API."

Slide 16

Slide 16 text

API Blueprint 4 Pure Markdown 4 Great tooling (including documentation generators) 4 Human readable, machine parsable 4 Example

Slide 17

Slide 17 text

Testing Your Documentation with DREDD "Dredd is a language agnostic command-line tool for validating API documentation written in API Blueprint format against its backend implementation."

Slide 18

Slide 18 text

Additional Tips 4 Each example is worth a page of documentation. Users should be able to quickly copy sample cURL requests and hit the ground running. 4 If the user is logged in and has a client registered, make all examples use their API key.

Slide 19

Slide 19 text

Favorite API Tools 4 Paw (OS X only) 4 Postman Safeguards 4 Rate-limiting by client and IP 4 HTTP 426 support (internal use)

Slide 20

Slide 20 text

API Support

Slide 21

Slide 21 text

4 Google Group 4 Stack Overflow tags 4 If a question comes up constantly, update the docs.

Slide 22

Slide 22 text

Other Approaches

Slide 23

Slide 23 text

4 HATEOAS 4 GraphQL

Slide 24

Slide 24 text

Links 4 Twitter's Pagination Setup 4 Stripe's API Versioning 4 Building Stripe's API

Slide 25

Slide 25 text

Questions? Comments? Thanks for listening and inviting me to speak! Slides and notes will be available at https://github.com/ jasdev/talks