- Another API-Blueprint, RAML and Swagger Comparison
- JSON
- Reverb - company behind the project
- API design approach - bottom-up (FIXME what does this mean?)
- API version metadata
- Scala for server and client code possible
- community stats favors...swagger (stackoverflow, github, google search for "swagger rest")
- OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
- Scalatra
- Ligthweight HTTP wrapper
- Excellent swagger support
- ScalatraSpec
.war
-based deployment
- Swagger support
- type-safe documentation
- contract-first API sandbox
- machine readable
- "A node, once deployed, cannot be changed"
- ScalaBay - API Design Antipatterns by Manish Pandit
- HTTP actions and their meanings
POST
to C reate or upsertGET
to R ead, retrieve, or searchPUT
(or better yetPATCH
) to U pdateDELETE
to D elete
- http://some.api.com/movies?start=0&count=10&sortBy=name&fields=name,cast,releaseDate
- HTTP codes antipatterns
- always return
HTTP 200 OK
{"success":false}
(!)
- always returning
HTTP 401 Unauthorized
for auth failures- Use
401
to indicate that the client needs to authenticate - Use
403 Forbidden
to indicate that the client's credentials don't allow access to the requested resource 401
to say "Come back with a key"403
to say "Your key doesn't fit the lock"
- Use
- always return
- General HTTP codes
2xx
for success3xx
for redirects/caching4xx
for request/client errors5xx
for server errors
- Useful yet less often used HTTP codes
204
for returning after a delete409
for failed database constraint405
for method not supported413
for trying to ask for too much data418
for validation failure
- Async operations and return
HTTP 202 Accepted
{"statusUrl" : <some URL>}
- Entities are not instances
- Namespace your resources in collection
- Use paths and identifiers to traverse
/pets/1234
for an instance 1234 of petsid
is implied
- other attributes in path
- HATEOAS
/resource/meta
or/collection/meta
for resource description (META pages)- Consider swagger or IODocs - documentation generators
- Accept cookies as a fallback, but prefer a query parameter or HTTP request header
- Stateless always
- Requests modify or read a resource
- Maintain state in database
- no transient state changes on server
- Versioning
301
to redirect/retire APIs
- Caching
- Use HTTP headers
- API Antipatterns : APICon SF by Manish Pandit
- Always specify a qualifier in the path when accessing resource(s) in a collection...except when accessing via the primary ID (it's implied)
/movies/name/{name}
/users/1234
/device/type/bdplayers
- Always think about the path to the resource as
/collection/resource identifier/value
- ...and manipulate it via verbs
- Resource properties in paths acceptable
/movies/rating/G
- Resource discovery via META pages
/collection/meta
/resource/meta
DELETE
fornull
ing a valueDELETE /movies/{id}/rating