Skip to content

phillbaker/gates

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gates

Build Status

This is an implementation of the ideas expressed in this post about Stripe's public API versioning, Move fast, don't break your API. The goal is to separate layers of request and response compatibility from the API logic, with two important drivers:

  • let your customers migrate API versions at their convenience, minimize the pain of upgrades when they do upgrade.
  • make it feasible to fix backward incompatible API schema mistakes (they will happen).

Installation

Add this line to your application's Gemfile:

gem 'gates'

And then execute:

$ bundle

Or install it yourself as:

$ gem install gates

Usage

Check for whether a gate is enabled:

version = request.api_version || user.api_version
version = Gates.for(version)
version.enabled?(:foo) # => true / false

Gates.available_versions # => [<Gates::ApiVersion ...>]

In CI make sure to lint the version manifest:

rake gates:lint

This can be combined with A/B testing or feature flipping like:

def foo
  return unless feature_enabled?(user, :foo) || ab_test?(:foo) || version.enabled?(:foo)

  "foo"
end
----
versions:
  -
    id: 2016-01-30-1
    gates:
      -
        name: reallows_amount
        description: |
          Just kidding. Sending amount is supported for some folks.
  -
    id: 2016-01-30
    gates:
      -
        name: disallows_amount
        description: |
          Sending amount is now deprecated.
  -
    id: 2016-01-20
    gates:
      -
        name: allows_amount
        description: |
          Sending amount is supported.

Testing

Make sure to test both paths in order to not break compatibility!

Similar projects

Contributing

  1. Fork it ( https://github.com/phillbaker/gates/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

About

Permanent backwards compatibility for changing APIs

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages