Skip to content

Instantly share code, notes, and snippets.

@st3v3nhunt
Last active October 23, 2018 12:31
Show Gist options
  • Save st3v3nhunt/726a62a4ac4bf9d8157f to your computer and use it in GitHub Desktop.
Save st3v3nhunt/726a62a4ac4bf9d8157f to your computer and use it in GitHub Desktop.
API design and documentation

Documented APIs:

Design:

Versioning:

4 main options:

  • URL
  • Accept Header
  • Custom Header
  • Query String

Thoughts on versioning:

Mark Nottingham - Chair of the Hypertext Transfer Protocol Bis Working Group HTTPbis WG. Mark has many thoughts on the subject, some of them listed below:

Proponents of URLs

Proponents of Accept Header:

Haters of Custom Header:

No particular opinion:

What do organisations do:

Organisation Versioning Method
GitHub Accept
Twitter URL
Facebook URL
Stripe URL & Custom
Instagram URL
Runkeeper Accept
Feedly URL
Foursquare URL & Query String
RottenTomatoes URL
Strava URL

Lexical Scope's view of the world here.

Summary:

Some considerations:

  • Can a JS client send the accept header in all browsers? Test this JSFiddle
  • Will proxies and other places where caching takes place cause problems if the headers are used to version?

Accept Header:

  • [+] Widely accepted this is a sound use case for the header
  • [-] Need to send back Vary header with Accept listed in order to ensure caches work

Custom Header:

  • [-] Potential conflict with other header
  • [-] Less support than using a standard Accept Header / not seen to be the way to do it

URL:

  • [+] Is a good way to version big changes
  • [+] It is really easy to see what version is being requested
  • [+] It is the most common, widely used mechanism
  • [+] A web browser can be used to change version being requested
  • [+] No worries about clients not being able to handle setting headers or caches becoming stale because they ignore headers

Closing thoughts:

It breaks down to 2 types of changes:

  1. Changes to the representation of the stuff (new properties added, old ones taken away).
  2. Changes to the resources of the stuff (new methods, options like query string params).

Using the URL to do versioning is an additional pressure on what URLs are already used to do. i.e. identify resources, provide links to other resource, be cache keys.

Overall...

  • Think about the future
  • Do not, unless absolutely neccessary, break stuff
  • Make everything backwards compatible
  • Aim to get things as correct as possible, from the earliest possible point
  • Think about what is being versioned - is it the resource or the representation?

Additional information:

http://www.digitalgov.gov/category/code/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment