beautiful rest+json apis with ion

126
Beautiful REST+JSON APIs with Ion Les Hazlewood @lhazlewood CTO, Stormpath, stormpath.com

Upload: stormpath

Post on 13-Jan-2017

1.058 views

Category:

Software


2 download

TRANSCRIPT

Page 1: Beautiful REST+JSON APIs with Ion

Beautiful REST+JSON APIswith Ion

Les Hazlewood @lhazlewoodCTO, Stormpath, stormpath.com

Page 2: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

.com• User Management API for Developers• Password security • Authentication and Authorization• LDAP/AD/Social/SAML/OAuth support• Instant-on, scalable, and highly available• Free for developers

Page 3: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Why REST?• Scalability• Generality• Independence• Latency (Caching)• Security• Encapsulation

Page 4: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Why JSON?• Ubiquity• Simplicity• Readability• Scalability• Flexibility

Page 5: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

REST Is Easy

Page 6: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

REST Is *&@#$! Hard(for providers)

Page 7: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

JSON – No Spec

Page 8: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

REST can be easy(if you follow some guidelines)

Page 9: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

HATEOAS• Hypermedia• As• The• Engine• Of• Application• State

Page 10: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

HATEOAS• Links• State Transitions

Page 11: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Fielding’s Requirementsroy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven:

• Communication Protocol Independent• Media Type Centric• No Fixed Names / Hierarchies• Dynamically Typed!• ZERO OUT-OF-BAND KNOWLEDGE

Page 12: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

How do we meet these requirements?

Page 13: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

How do we...?Base URLVersioningResource FormatReturn ValuesContent NegotiationReferences (Linking)PaginationQuery ParametersCreate/UpdateSearchAssociations

ErrorsIDsMethod OverloadingResource ExpansionPartial ResponsesCaching & EtagsSecurityMulti TenancyMaintenanceBatch Operations

Page 14: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Fundamentals

Page 15: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

ResourcesNouns, not Verbs

Coarse Grained, not Fine Grained

Architectural style for use-case scalability

Page 16: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

What If?/getAccount

/createDirectory

/updateGroup

/verifyAccountEmailAddress

Page 17: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

What If?/getAccount/getAllAccounts/searchAccounts/createDirectory/createLdapDirectory/updateGroup/updateGroupName/findGroupsByDirectory/searchGroupsByName/verifyAccountEmailAddress/verifyAccountEmailAddressByToken…Smells like bad RPC. DON’T DO THIS.

Page 18: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Keep It Simple

Page 19: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

The AnswerFundamentally two types of resources:

Collection Resource

Instance Resource

Page 20: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Collection Resource

/applications

Page 21: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Instance Resource

/applications/a1b2c3

Page 22: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Behavior• GET• PUT• POST• DELETE• HEAD

Page 23: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

BehaviorPOST, GET, PUT, DELETE

≠ 1:1Create, Read, Update, Delete

Page 24: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

BehaviorAs you would expect:

GET = ReadDELETE = DeleteHEAD = Headers, no Body

Page 25: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

BehaviorNot so obvious:

PUT and POST can both be used forCreate and Update

Page 26: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

PUT for CreateIdentifier is known by the client:

PUT /applications/clientSpecifiedId

{ …}

Page 27: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

PUT for UpdateFull Replacement

PUT /applications/existingId

{ “name”: “Best App Ever”, “description”: “Awesomeness”}

Page 28: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

PUT

Idempotent

Page 29: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

POST as CreateOn a parent resource

POST /applications

{ “name”: “Best App Ever”}

Response:

201 CreatedLocation: https://api.stormpath.com/applications/a1b2c3

Page 30: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

POST as UpdateOn instance resource

POST /applications/a1b2c3

{ “name”: “Best App Ever. Srsly.”}

Response:

200 OK

Page 31: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

POST

NOT Idempotent

Page 32: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Media Types• Format Specification + Parsing Rules• Request: Accept header• Response: Content-Type header

• application/json• application/ion+json• application/ion+json;v=2• …

Page 33: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Design Time!

Page 34: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

HATEAOS in JSON: Ion

Page 35: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Resources

Page 36: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Object{ “firstName”: “Bob”, “lastName”: “Smith”, “birthDate”: “1980-01-23”,}

Page 37: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Ion Object{ “meta”: { ... }, “firstName”: “Bob”, “lastName”: “Smith”, “birthDate”: “1980-01-23”,}

Page 38: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Naïve collection (not recommended)“items”: []

Page 39: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Collection Object{ “items”: []}

Page 40: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Ion Collection{ “meta”: { ... }, “items”: []}

Page 41: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Linking

Page 42: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

HREF• Distributed Hypermedia is paramount!

• Every accessible Resource has a canonical unique URL

• Replaces IDs (IDs exist, but are opaque).

• Critical for linking

Page 43: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Linking in JSON?• XML has it (XLink), JSON doesn’t• How do we do it?

Page 44: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Naïve linking

Page 45: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Naïve linking - instanceGET /accounts/x7y8z9

200 OK

{ “givenName”: “Tony”, “surname”: “Stark”, …, “directory”: ????}

Page 46: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Naïve linking - instance cont’dGET /accounts/x7y8z9

200 OK

{ “givenName”: “Tony”, “surname”: “Stark”, …, “directory”: { “href”: “https://api.stormpath.com/v1/directories/g4h5i6” }}

Page 47: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Naïve linking - collectionGET /accounts/x7y8z9

200 OK

{ “givenName”: “Tony”, “surname”: “Stark”, …, “groups”: { “href”: “https://api.stormpath.com/accounts/x7y8z9/groups” }}

Page 48: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Ion linking (recommended)

Page 49: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Ion meta hrefGET /accounts/x7y8z9

200 OK{ “meta”: { “href”: “https://api.stormpath.com/accounts/x7y8z9” }, “givenName”: “Tony”, “surname”: “Stark”, …}

Page 50: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Ion link GET /accounts/x7y8z9

200 OK{ “meta”: { ... }, “givenName”: “Tony”, “surname”: “Stark”, …, “directory”: { “meta”:{ “href”: https://api.stormpath.com/directories/g4h5i6” } }}

Page 51: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Ion link (collection)GET /accounts/x7y8z9

200 OK{ “meta”: { ... }, “givenName”: “Tony”, “surname”: “Stark”, …, “groups”: { “meta”: { “href”: “https://api.stormpath.com/accounts/x7y8z9/groups”, “rel”: [“collection”] } }}

Page 52: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

What about HAL?• Linking focus• Forces links to be separate from context/content– (when was the last time you had to put all of your

anchors at the bottom of an html paragraph? Right... never.)

• In contrast to HAL, Ion is much more like HTML – it’s all in one convenient spec.

• Ion transliteration to/from HTML is far easier (by design)

Page 53: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

State Transitions

Page 54: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Creating And Updating

Page 55: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Remember HATEOS?

Page 56: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

“Let me go read the docs to figure out how to POST”

Page 57: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

NO! This is not HATEOS.

Page 58: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

How do browsers work?

Page 59: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Forms

Page 60: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Forms: Create{ “foo”: “bar”, “baz”: “boo”, ...

“createAccount”: { “meta”: {“href”: “https://foo.io/users”, “rel”: [“create-form”], “method”: “POST”}, “items”: [ {“name”: “login”, “required”: “true”, “label”: “Username or Email” }, {“name”: “password”, “secret”: “true”, “required”: “true”, “label”: “Password”} ] }}

Page 61: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Forms: Create cont’d{ "meta": {"href": "https://example.io/users", "rel":["create-form"], "method":"POST"}, "items": [ {"name":"username"}, {"name": "password", "secret": true }, {"name": "visitedContinents","type": "set", "minitems": 1,"maxitems": 7,"options": { "items": [ {"label": "Africa", "value": "af" }, {"label": "North America", "value": "na" }, {"label": "South America", "value": "sa" }, {"label": "Europe", "value": "eu" }, {"label": "Asia", "value": "as" }, {"label": "Oceania", "value": "oc" }, {"label": "Antarctica", "value": "an" }, ] } } ]}

Page 62: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Forms: Search / Query{ ...

“findAccounts”: { “meta”: { “href”: “https://foo.io/users”, “rel”: [“search-form”], “method”: “GET” }, “items”: [ {“name”: “username”, “label”: “Username”}, {“name”: “email”, “type”: “email”, “label”: “Email” }, {“name”: “givenName”, “label”: “First Name” }, {“name”: “surname”, “label”: “Last Name”}, ] }}

Page 63: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

What about Schemas / json-schema ?

Not needed. REST != RDBMS(are schemas necessary for browsers/HTML?)

Forms do the same thing and are more flexible/powerful

Remember Fielding’s REST Rule about Dynamic Typing

Page 64: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

HTTP Protocol Semantics

Page 65: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Base URL

Page 66: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

http(s)://foo.io

vs

http://www.foo.com/dev/service/api/rest

Page 67: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

http(s)://foo.io

Rest Clientvs

Browser

Page 68: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Versioning

Page 69: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

URL https://api.stormpath.com/v1

vs.

Media-Typeapplication/jsonapplication/ion+json

Page 70: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Content Negotiation

Page 71: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Header• Accept header• Header values comma delimited• q param determines precedence, defaults to 1,

then conventionally by list order

GET /applications/a1b2c3Accept: application/json, text/plain;q=0.8

Page 72: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Resource Extension/applications/a1b2c3.json/applications/a1b2c3.csv…

Conventionally overrides Accept header

Page 73: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Style Guide

Page 74: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

camelCase‘JS’ in ‘JSON’ = JavaScript

myArray.forEach Not myArray.for_each

account.givenNameNot account.given_name

Underscores for property/function names are unconventional for JS. Stay consistent.

Page 75: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Dates & Times

Page 76: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Dates & TimesThere’s already a standard. Use it: ISO 8601

“createdAt”: “2013-07-10T18:02:24.343Z”

Use UTC!

This is represented in Ion as a field types of date, time, datetime, etc.

Page 77: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

createdAt / updatedAtMost people will want this at some point

{ …, “createdAt”: “2013-07-10T18:02:24.343Z”, “updatedAt”: “2014-09-29T07:02:48.761Z”}

Use UTC!

Page 78: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Reference Expansion(aka Entity Expansion, Link Expansion)

Page 79: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Account and its Directory?

Page 80: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

GET /accounts/x7y8z9?expand=directory

200 OK{ “meta”: {..., “expandable”: [“directory”,...] }, “givenName”: “Tony”, “surname”: “Stark”, …, “directory”: { “meta”: { ... }, “name”: “Avengers”, “description”: “Hollywood’s plan for more $”, “createdAt”: “2012-07-01T14:22:18.029Z”, … }}

Page 81: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Collection Pagination

Page 82: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Ensure Collection Resources support query params:• Offset + Limit vs Cursor

…/applications?offset=50&limit=25

• Don’t require the user to query for these – provide OOTB links

Page 83: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

GET /accounts/x7y8z9/groups

200 OK{ “meta”: { ... }, “offset”: 0, “limit”: 25, “first”: { “meta”:{“href”: “…/accounts/x7y8z9/groups?offset=0”}}, “previous”: null, “next”: { “meta”:{“href”: “…/accounts/x7y8z9/groups?offset=25”}}, “last”: { “meta”:{“href”: “…”}}, “items”: [ { “meta”: { “href”: “…”, ...} }, { “meta”: { “href”: “…”, ...} }, … ]}

Page 84: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Sorting

Page 85: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

GET .../accounts? orderBy=surname,givenName%20desc

Page 86: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Search

Page 87: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

“Find all accounts with a ‘company.com’ email

address that can login to a particular application”

Page 88: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

GET /applications/x7y8z9/accounts?email=*company.com

200 OK{ “meta”: { ... }, “offset”: 0, “limit”: 25, “first”: { “meta”:{ “href”:“/applications/x7y8z9/accounts?email=*company.com&offset=0”} }, “previous”: null, “next”: { “meta”:{ “href”: “/applications/x7y8z9/accounts?email=*company.com&offset=25”} }, “last”: { “meta”:{“href”: “…”}}, “items”: [ { “meta”: { “href”: “…”, ...} }, { “meta”: { “href”: “…”, ...} }, … ]}

Page 89: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Search cont’d• Filter search

.../accounts?q=some+value

• Attribute Search.../accounts?surname=Joe&email=*company.com

Page 90: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Search cont’d• Starts with

?email=joe*

• Ends with

?email=*company.com

• Contains (warning! Bad performance)

?email=*foo*

Page 91: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Search cont’d• Range queries via Ion min and max field members

“all accounts created between September 1st and the 15th”

Form fields example:

{“name”: “createdAtBegin”, “min”: “2014-01-01”,”max=“2014-12-31”}{“name”: “createdAtEnd”, “min”: “2014-01-01”,”max=“2014-12-31”}

Ion TBD: range type:.../accounts?createdAt=[2014-09-01,2014-09-15]

Page 92: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Search cont’d• Use Ion forms and the pattern form field member

to represent search expressions

Page 93: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Many To Many

Page 94: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Group to Account• A group can have many accounts• An account can be in many groups• Each mapping is a resource:

GroupMembership

Page 95: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

GET /groupMemberships/23lk3j2j3

200 OK{ “meta”:{“href”: “…/groupMemberships/23lk3j2j3”}, “account”: { “meta”:{“href”: “…”} }, “group”: { “meta”{“href”: “…”} }, …}

Page 96: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

GET /accounts/x7y8z9

200 OK{ “meta”:{“href”: “…/accounts/x7y8z9”}, “givenName”: “Tony”, “surname”: “Stark”, …, “groups”: { “meta”:{“href”: “…/accounts/x7y8z9/groups” “rel”: [“collection”]} }, “groupMemberships”: { “meta”:{“href”: “…/groupMemberships?accountId=x7y8z9”,”rel”:[“collection”]} }}

Page 97: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Async or Long-Lived Operations

Page 98: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

POST /emails

{ “from”: [email protected], “subject”: “Hi!” “body”: “...”}

Page 99: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

204 AcceptedLocation: /emails/23Sd932sSl

{ “status”: “queued”, ...}

Page 100: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

GET /emails/23Sd932sSlExpires: 2014-09-29T18:00:00.000Z

{ “status”: “sent”, ...}

Page 101: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Batch Operations

Page 102: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

• Each batch is represented as a resource

• Batches are likely to be a collection

• Batches are likely to have a status

• Downside: problematic regarding HTTP caching

Page 103: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Batch Delete“Delete all company.com accounts”

DELETE /accounts? email=*@company.com

Page 104: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Batch Create / UpdateAlready have a Collection concept. Use it.

Page 105: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Batch Create or UpdatePOST /accounts

{ “meta”: { ... }, “items”: [ { ... account 1 ... }, { ... account 2 ... }, ... ]}

Page 106: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Batch Operations: The ‘Catch’HTTP Caching is bypassed entirely

Page 107: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

204 AcceptedLocation: /batches/a1b2c3

{ “status”: “processing”, //overall status “size”: “n”, “limit”: 25, ..., “items”: { { response 1 (w/ individual status) ...}, { response 2 (w/ individual status) ...}, ... }}

Page 108: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Errors

Page 109: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

• As descriptive as possible• As much information as possible• Developers are your customers

Page 110: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

POST /directories

409 Conflict

{ “status”: 409, “code”: 40924, “property”: “name”, “message”: “A Directory named ‘Avengers’ already exists.”, “developerMessage”: “A directory named ‘Avengers’ already exists. If you have a stale local cache, please expire it now.”, “moreInfo”: “https://www.stormpath.com/docs/api/errors/40924”}

Page 111: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Security

Page 112: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Avoid sessions when possibleAuthenticate every request if necessaryStateless

Authorize based on resource content, NOT URL!

Use Existing Protocol:Oauth 1.0a, Oauth2, Basic over SSL only

Custom Authentication Scheme:Only if you provide client code / SDKOnly if you really, really know what you’re doing

Use API Keys and/or JWTs instead of Username/Passwords

Page 113: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

401 vs 403• 401 “Unauthorized” really means Unauthenticated

“You need valid credentials for me to respond to this request”

• 403 “Forbidden” really means Unauthorized

“Sorry, you’re not allowed!”

Page 114: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

HTTP Authentication Schemes• Server response to issue challenge:

WWW-Authenticate: <scheme name> realm=“Application Name”

• Client request to submit credentials:

Authorization: <scheme name> <data>

Page 115: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

API Keys• Entropy• Password Reset• Independence• Scope• Speed• Limited Exposure• Traceability

Page 116: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

IDs

Page 117: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

• IDs should be opaque• Should be globally unique• Avoid sequential numbers (contention, fusking)• Good candidates: UUIDs, ‘Url64’

Page 118: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

HTTP Method Overrides

Page 119: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

POST /accounts/x7y8z9?_method=DELETE

Page 120: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Caching & Concurrency Control

Page 121: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Server (initial response): ETag: "686897696a7c876b7e”

Client (later request):If-None-Match: "686897696a7c876b7e”

Server (later response):304 Not Modified

Page 122: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Maintenance

Page 123: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Use HTTP Redirects

Create abstraction layer / endpoints when migrating

Use well defined custom Media Types

Page 124: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

IETF RFC?

Page 125: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

Ion Media Type

ionwg.org/draft-ion.html

Page 126: Beautiful REST+JSON APIs with Ion

@lhazlewood @goStormpath

.com• Free for developers• Eliminate months of development• Automatic security best practices• Single Sign On• Social/OAuth/SAML/Multi-factor/etc• API Authentication & Key Management• Token Authentication for SPAs / Mobile• Authorization & Multi-tenancy for your apps

Libraries and integrations: https://docs.stormpath.com