All Projects → Nebo15 → Multiverse

Nebo15 / Multiverse

Licence: mit
Elixir package that allows to add compatibility layers via API gateways.

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to Multiverse

Pinned
📌 Date based versioning system for Go APIs.
Stars: ✭ 77 (-11.49%)
Mutual labels:  api, versioning
Versioncake
🍰 Version Cake is an unobtrusive way to version APIs in your Rails or Rack apps
Stars: ✭ 623 (+616.09%)
Mutual labels:  api, versioning
Rust rocket api authentication
An example of API written in Rust with the rocket.rs framework, with a JWT Authentication
Stars: ✭ 82 (-5.75%)
Mutual labels:  api
Cats
Generate tests at runtime based on OpenApi specs
Stars: ✭ 86 (-1.15%)
Mutual labels:  api
Stringlifier
Stringlifier is on Opensource ML Library for detecting random strings in raw text. It can be used in sanitising logs, detecting accidentally exposed credentials and as a pre-processing step in unsupervised ML-based analysis of application text data.
Stars: ✭ 85 (-2.3%)
Mutual labels:  api
Bhagavadgita
A non-profit initiative to help spread the transcendental wisdom from the Bhagavad Gita to people around the world.
Stars: ✭ 84 (-3.45%)
Mutual labels:  api
Deep Learning Training Gui
Train and predict your model on pre-trained deep learning models through the GUI (web app). No more many parameters, no more data preprocessing.
Stars: ✭ 85 (-2.3%)
Mutual labels:  api
Terraformize
Apply\Destory Terraform modules via a simple REST API endpoint.
Stars: ✭ 84 (-3.45%)
Mutual labels:  api
Spotify Web Api Kotlin
Spotify Web API wrapper for Kotlin/JVM, Kotlin/Android, Kotlin/JS, and Kotlin/Native. Includes a Spotify Web Playback SDK wrapper for Kotlin/JS, and a spotify-auth wrapper for Kotlin/Android
Stars: ✭ 86 (-1.15%)
Mutual labels:  api
Node Google Dfp
A service for integrating with Google DFP over NodeJS
Stars: ✭ 84 (-3.45%)
Mutual labels:  api
Core
Open source Dota 2 data platform
Stars: ✭ 1,266 (+1355.17%)
Mutual labels:  api
Node Api Cn
Node.js API 中文文档
Stars: ✭ 1,259 (+1347.13%)
Mutual labels:  api
Iota.lib.cpp
IOTA C++ Library
Stars: ✭ 84 (-3.45%)
Mutual labels:  api
Dunamai
Dynamic versioning library and CLI
Stars: ✭ 85 (-2.3%)
Mutual labels:  versioning
Node Epicgames Client
Unofficial EpicGames Launcher in javascript.
Stars: ✭ 84 (-3.45%)
Mutual labels:  api
Pypistats
Command-line interface to PyPI Stats API to get download stats for Python packages
Stars: ✭ 86 (-1.15%)
Mutual labels:  api
Apiinspect
An api compatibility inspect gradle plugin.(一个Api兼容性检测的Gradle插件)
Stars: ✭ 84 (-3.45%)
Mutual labels:  api
Mezzanine Api
RESTful web API for Mezzanine CMS
Stars: ✭ 84 (-3.45%)
Mutual labels:  api
Bigbluebutton
Package that provides easily communicate between bigbluebutton server and laravel framework
Stars: ✭ 85 (-2.3%)
Mutual labels:  api
Meting
🍰 Wow, such a powerful music API framework
Stars: ✭ 1,265 (+1354.02%)
Mutual labels:  api

Multiverse

Deps Status Hex.pm Downloads Latest Version License Build Status Coverage Status Ebert

This plug helps to manage multiple API versions based on request and response gateways. This is an awesome practice to hide your backward compatibility. It allows to have your code in a latest possible version, without duplicating controllers or models. We use it in production.

Compatibility Layers

Inspired by Stripe API. Read more at MOVE FAST, DON'T BREAK YOUR API or API versioning.

Goals

  • reduce changes required to support multiple API versions;
  • provide a way to test and schedule API version releases;
  • to have minimum dependencies and low performance hit;
  • to be flexible enough for most of projects to adopt it.

Adapters

Multiverse allows you to use a custom adapter which can, for eg.:

  • store consumer version upon his first request and re-use it as default each time consumer is using your API, eliminating need of passing version headers for them (a.k.a. version pinning). Change this version when consumer has explicitly set it;
  • use other than ISO date version types, eg. incremental counters (v1, v2);
  • handle malformed versions by responding with JSON errors.

Default adapter works with ISO-8601 date from x-api-version header (configurable). For malformed versions it would log a warning and fallback to the default date (configured via :default_version setting):

  • :first - apply all gates by default. This option is useful when you integrate Multiverse in existing project and API consumers are not ready to accept latest changes by default;
  • :latest - user current date as default version. This option is useful when there are no legacy clients or there was no breaking changes before those clients started to send API version.

ISO date adapter allows API clients to use channel name instead of date:

  • latest channel would fallback to the current date;
  • edge channel would disable all changes altogether.

Channels allow you to plan version releases upfront and test them without affecting users, just set future date for a change and pass it explicitly or use edge channel to test latest application version.

Installation

The package (take look at hex.pm) can be installed as:

  1. Add multiverse to your list of dependencies in mix.exs:
def deps do
  [{:multiverse, "~> 2.0.0"}]
end
  1. Make sure that multiverse is available at runtime in your production:
def application do
  [applications: [:multiverse]]
end

How to use

  1. Insert this plug into your API pipeline (in your router.ex):
pipeline :api do
  plug :accepts, ["json"]
  plug :put_secure_browser_headers

  plug Multiverse, default_version: :latest
end
  1. Define module that handles change
defmodule AccountTypeChange do
  @behaviour Multiverse.Change

  def handle_request(%Plug.Conn{} = conn) do
    # Mutate your request here
    IO.inspect "AccountTypeChange.handle_request applied to request"
    conn
  end

  def handle_response(%Plug.Conn{} = conn) do
    # Mutate your response here
    IO.inspect "AccountTypeChange.handle_response applied to response"
    conn
  end
end
  1. Enable the change:
pipeline :api do
  plug :accepts, ["json"]
  plug :put_secure_browser_headers

  plug Multiverse,
    default_version: :latest,
    gates: %{
      ~D[2016-07-21] => [AccountTypeChange]
    }
end
  1. Send your API requests with X-API-Version header with version lower or equal to 2016-07-20.

Overriding version header

You can use any version headers by passing option to Multiverse:

pipeline :api do
  plug :accepts, ["json"]
  plug :put_secure_browser_headers

  plug Multiverse,
    default_version: :latest,
    version_header: "x-my-version-header",
    gates: %{
      ~D[2016-07-21] => [AccountTypeChange]
    }
end

Using custom adapters

You can use your own adapter which implements Multiverse.Adapter behaviour:

pipeline :api do
  plug :accepts, ["json"]
  plug :put_secure_browser_headers

  plug Multiverse,
    default_version: :latest,
    adapter: MyApp.SmartMultiverseAdapter,
    gates: %{
      ~D[2016-07-21] => [AccountTypeChange]
    }
end

Structuring your tests

  1. Split your tests into versions:
$ ls -l test/acceptance
total 0
drwxr-xr-x  2 andrew  staff  68 Aug  1 19:23 AccountTypeChange
drwxr-xr-x  2 andrew  staff  68 Aug  1 19:24 OlderChange
  1. Avoid touching request or response in old tests. Create API gates and matching folder in acceptance tests.

Other things you might want to do

  1. Store Multiverse configuration in config.ex:
use Mix.Config

config :my_app, MyApp.Endpoint,
  default_version: :latest,
  gates: %{
    ~D[2016-07-21] => [AccountTypeChange]
  }
plug Multiverse, otp_app: :my_app, endpoint: __MODULE__
  1. Generate API documentation from changes @moduledoc's.

  2. Other awesome stuff. Open an issue and tell me about it! :).

License

See LICENSE.md.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].