Skip to content

crepe/crepe-versioning

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

crepe-versioning Build Status Code Climate

Add versioning support to your Crepe APIs.

Installation

In your Gemfile:

gem 'crepe-versioning'

Usage

crepe-versioning supports three different versioning strategies:

  • In the path (the default)
  • In the Accept header
  • In a query parameter
require 'crepe'
require 'crepe/versioning'

# Demonstrates versioning your API in several ways:
#
#   $ curl 0.0.0.0:9292/?v=v1
#   {"message":"Version 1"}
#   $ curl 0.0.0.0:9292/v2
#   {"message":"Version 2"}
#   $ curl -H 'Accept: application/vnd.crepe-3+json' 0.0.0.0:9292
#   {"message":"Version 3"}
class Versioned < Crepe::API
  # Equivalent to `version :v2 do ... end`
  version :v2, with: :path do
    get do
      { message: 'Version 2' }
    end
  end

  # Experimental version 3
  version :v3, with: :header, vendor: 'crepe' do
    get do
      { message: 'Version 3' }
    end
  end

  version :v1, with: :query, name: 'v' do
    get do
      { message: 'Version 1' }
    end
  end
end

run Versioned

The first defined version will be the default version (:v2, in the above case). You can also set namespace-wide configuration for your versions, including setting a default. For example:

require 'crepe'
require 'crepe/versioning'

# Demonstrates less repetitive version configuration:
#
#   $ curl 0.0.0.0:9292
#   {"message":"Version 2"}
#   $ curl -H 'Accept: application/vnd.crepe-1+json' 0.0.0.0:9292
#   {"message":"Version 1"}
class Versioned < Crepe::API
  version with: :header, vendor: 'crepe', default: :v2

  version :v1 do
    get do
      { message: 'Version 1' }
    end
  end

  version :v2 do
    get do
      { message: 'Version 2' }
    end
  end
end

run Versioned

License

crepe-versioning is licensed under The MIT License.

Releases

No releases published

Packages

No packages published

Languages