Git Product home page Git Product logo

versioning's Introduction

Versioning

Build Status Versioning Version

Versioning provides a way for API's to remain backward compatible without the headache.

This is done through use of a "versioning schema" that translates data through a series of steps from its current version to the target version. This technique is well described in the article APIs as infrastructure: future-proofing Stripe with versioning.

The basic rule is each API version in the schema must only ever concern itself with creating a set of change modules associated with the version below/above it. This contract ensures that we can continue to translate data to legacy versions without enormous effort.

Installation

The package can be installed by adding versioning to your list of dependencies in mix.exs:

def deps do
  [
    {:versioning, "~> 0.4"}
  ]
end

Documentation

See HexDocs for additional documentation.

Example

For a more in-depth example, please check out the Getting Started page.

We build a schema to describe updates to our API through versions, types, and changes.

defmodule MyAPI.Versioning do
  use Versioning.Schema

  version("1.2.0", do: [])

  version "1.1.0" do
    type "Post" do
      change(MyAPI.Changes.PostStatusChange)
    end
  end

  version("1.0.0", do: [])
end

We build a change module to perform data modifications.

defmodule MyAPI.Changes.PostStatusChange do
  use Versioning.Change

  @desc """
  The boolean field "active" was removed in favour of the enum "status".
  """

  def down(versioning, _opts) do
    case Versioning.pop_data(versioning, "status") do
      {"active", versioning} -> Versioning.put_data(versioning, "active", true)
      {_, versioning} -> Versioning.put_data(versioning, "active", false)
    end
  end

  def up(versioning, _opts) do
    case Versioning.pop_data(versioning, "active") do
      {true, versioning} -> Versioning.put_data(versioning, "status", "active")
      {false, versioning} -> Versioning.put_data(versioning, "status", "hidden")
      {_, versioning} -> versioning
    end
  end
end

We create versionings to run against our schema. Here, we want to change our post data from version 1.2.0 to 1.0.0. We can then run our versioning against the schema, which will return a modified versioning with our change modules run.

versioning = Versioning.new(%Post{}, "1.2.0", "1.0.0")
MyAPI.Versioning.run(versioning)

Phoenix Usage

Versioning provides extensive support for usage with Phoenix. Checkout the Phoenix Usage page for more details.

versioning's People

Contributors

nsweeting avatar

Stargazers

Eliel Haouzi avatar Sergio Mattei avatar Kyle Nathan avatar Mahmoud Rusty Abdelkader avatar Takeshi avatar James Stephens avatar Garrett Tacoronte avatar Menegazzi avatar Phillipp Ohlandt avatar Aeryn Riley Dowling-Toland avatar Dmitry Ledentsov avatar Grant McLendon avatar Mikkel H Madsen avatar Chris McGrath avatar Unnawut Leepaisalsuwanna avatar Esdras Mayrink avatar Brian Mathiyakom avatar Fernando Mumbach avatar Caleb Williams avatar Israel Santiago avatar COHAWK avatar Renê Schneider avatar Vitaliy V. Shopov avatar Just Manny avatar Sam Gaw avatar Павел "Malo" Скрылёв  avatar Allan MacGregor avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.