api design

22

Upload: dom-udall

Post on 19-May-2015

751 views

Category:

Technology


5 download

DESCRIPTION

Basics of good API design (font not embedded correctly, so sorry it looks nasty!)

TRANSCRIPT

Page 1: API Design
Page 2: API Design

API Design

Page 3: API Design

Who Am I?

Bournemouth Uni Graduate

Clock – Software Engineer

Synth Media – Technical Director

@synthmedia – Business

@domudall – Srs

@dmno – Not so srs

http://github.com/domudall Dom Udall

Page 4: API Design

Apologies

Page 5: API Design

Where I’ve Stolen This From

http://www.slideshare.net/MikePearce/api-anti-patterns-4920731https://vimeo.com/13922981

http://mikepearce.net/

Page 6: API Design

REST

verb noun

Page 7: API Design

GET/POST Tunnelling

• GET• POST• PUT• DELETE• HEAD

• TRACE• OPTIONS• CONNECT• PATCH

http://en.wikipedia.org/wiki/HTTP_method#Request_methods

Page 8: API Design

PUT or POST

“The client uses PUT when it’s in charge of deciding which new URI the resource should have. The client uses POST when the server is in charge…”

O’Reillys RESTful web services

Page 9: API Design

Responsible Responses

• Send the correct content type header

• Don’t send mixed responses

• Use the correct response code!

Page 10: API Design

Response Codes

• 1xx – Informational

• 2xx – Successful• 3xx – Redirection• 4xx – Client Error• 5xx – Server Error

http://en.wikipedia.org/wiki/List_of_HTTP_status_codes

Page 11: API Design

Caching

• Between application and database

• In the application itself• Using an API proxy• CDN for large static content

Page 12: API Design

Cookies

• NO!• REST is meant to be

stateless• One change to token

handling can render all tokens useless

Page 13: API Design

HATEOAS

Hypermedia as the engine of application state

Huh?

Page 14: API Design

HATEOAS

• Clients shouldn’t be building URIs

• API responses return end points

• API end points can change without disruption to the client

Page 15: API Design

GET: http://api.startup.co/users

Page 16: API Design

Versioning

• Grey area• Goes against HATEOAS• Can either:– Versioning all URIs– Not versioning main URI– Not versioning at all

Page 17: API Design

Document Extensions

• Use file extensions to denote content type

OR

• Use ‘Accept’ headers

Page 18: API Design

Document!

• xDoc – Not so useful for end point docs

• I/O Docs – Great, but not linked to code

• Swagger – Very similar to I/O Docs• Grape – Ruby REST-like API

generator

Page 19: API Design

Security

• Use something established• API keys for non-sensitive data

only• Username/password auth for

site based APIs• OAuth for server-to-server APIs• SSL for EVERYTHING sensitive

Page 20: API Design

Summary

An APIs job is to make a developer as successful as

possible, as quickly as possible

Page 21: API Design

Thanks!

Page 22: API Design

Q&A?