The Gotchas of

RESTful API

design

Philip De Smedt

Slide theme "borrowed" from Alicia Liu

Building an API from scratch

Fuzzy Standards

Requirements to strive for

  • Simple, Intuitive, Consistent

  • Friendly to the developer

  • Explorable in a browser

Good API Designs

http://jsonapi.org/

Good API Designs

http://stateless.co/hal_specification.html

API Versioning

ALWAYS

version your API

URL or HEADER?

MGMT versus STABILITY!

Return a RESOURCE REPRESENTATION

POST / PUT / PATCH

POST?

  • HTTP Status Code

  • Location Header

Ditch XML

  • Verbose

  • Hard to read and parse

Google Trends: XML vs JSON API

HATEOAS

HyperText as the Engine of Application State

Discoverability of actions

The WEB does this.

Why not APIs?

Decision at

Run-Time

versus

Code-Time

Pro

or

Contra

Hypermedia APIs

Hypermedia doesn't have to be difficult

HAL

HyperText Application Language

Links on top of JSON

          
            {
              "_links": {
                "attendees": { "href": "..." },
                "speakers": { "href": "..." }
              },
              "id": 9999,
              "date": "2014-03-27"
              "name": "API Strategy Conference"
            }
          
        

Link Relations

Lifeblood of a Hypermedia API

The idea is that a developer can enter into your API, read through documentation for the available links, and then follow-their-nose through the API.

Hypermedia Resources

RESTful Web APIs

by L. Richardson et al

Designing Hypermedia APIs

by Steve Klabnik

Thanks!

Philip De Smedt

@philipdesmedt