Slide 1

Slide 1 text

The Dream of the 90’s is Withering on the Vine (in Portland)

Slide 2

Slide 2 text

How to Future-Proof & Increase The Level of Sanity in the Design of Your APIs, by Respecting the Best Practices of HTTP Or...

Slide 3

Slide 3 text

This is Roy

Slide 4

Slide 4 text

Principles • Client-Server • Stateless • Cacheable • Uniform Interface • Opaque Layering • Code-on-Demand

Slide 5

Slide 5 text

Objectives •Auth •Querying •Relationships •Pagination •Formats •Caching •Logging •API Versioning

Slide 6

Slide 6 text

Auth •Simple! •Basic vs. Digest (over SSL, obviously) •Upshot of Basic: http://user:[email protected]/objects •Cookies? •Custom Tokens?

Slide 7

Slide 7 text

Querying •There are approaches to making this discoverable •They are ridiculously ivory-tower •Better: ?q=

Slide 8

Slide 8 text

Relationships •Goal: Introspect API domain model and transform object relationships to URLs

Slide 9

Slide 9 text

Relationships GET /tasks HTTP/1.1 [{ title: "Finish client demo", completed: false, _links: { self: { href: "http://my.app/tasks/1138" }, owner: { href: "http://my.app/users/nate" }, subtasks: { href: "http://my.app/tasks/1138/subtasks" } } }]

Slide 10

Slide 10 text

Pagination GET /tasks?page=5&order=due ?

Slide 11

Slide 11 text

Pagination HTTP Range! GET /videos/rickroll.mp4 Range: bytes=100-99999

Slide 12

Slide 12 text

Pagination HEAD /tasks HTTP/1.1 ... HTTP 200 OK Accept-Ranges: tasks

Slide 13

Slide 13 text

Pagination HEAD /posts HTTP/1.1 ... HTTP 200 OK Accept-Ranges: posts

Slide 14

Slide 14 text

Pagination GET /posts HTTP/1.1 Range: posts=1-20

Slide 15

Slide 15 text

Caching (Strategies) • Generated cache keys (ETag, If-None-Match) • For writes: If-Match • Time-based (Last-Modified / If-Modified-Since)

Slide 16

Slide 16 text

Logging Custom Response Headers!

Slide 17

Slide 17 text

Logging X-Query-Log: SELECT * From users WHERE name = "nate" X-Query-Log: SELECT * From tasks WHERE user_id = 13

Slide 18

Slide 18 text

Logging X-Query-Log: users.find({ name: "nate" })

Slide 19

Slide 19 text

DEMO