Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

versioner_rails

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

versioner_rails

  • 1.0.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

versioner-rails

API versioning that promotes convention over configuration.

The premise of this gem is that consumers of your API need versioning and different shapes of your resources. Without proper thought into versioning and shaping, your codebase can quickly resolve into a redundant and confusing state. This gem tries to solve that problem by allowing the API owner to use simple conventions -- Accept headers and ActiveModelSerializer namespacing -- to achieve controller reuse by controllers delegating resource versioning and shaping to the serializer level.

example

Let's say we have a resource of type Foo and foos_controller.rb that includes our gem and has a show action:

class FoosController < ActionController::Base
  versioner Serializers::Foo

  def show
    render json: Foo.new(first_name: 'Shawn'), serializer: versioner_serializer
  end

end

A client on v1 would like a list of foos in short form:

curl http://localhost:3000/foos -H 'Accept: application/javascript; version=1 shape=short'

A client on v2 would like a list of foos in short form:

curl http://localhost:3000/foos -H 'Accept: application/javascript; version=2 shape=short'

A client on v1 would like a list of foos in full form:

curl http://localhost:3000/foos -H 'Accept: application/javascript; version=1 shape=full'

A client on v2 would like a list of foos in default form:

curl http://localhost:3000/foos -H 'Accept: application/javascript; version=2

Assuming we have the following ActiveModelSerializer directory structure, we wouldn't have to change the above controller at all to fulfill these requests:

app
  serializers
    foo
      v1
        foo_short_serializer.rb
        foo_full_serializer.rb
      v2
        foo_full_serializer.rb
        foo_serializer.rb

To specify that the versioner should be applied to or excluded from given controller actions, use the :only and :except parameters.

versioner Serializers::Foo, :except => [:index, :show]
versioner Serializers::Foo, :only => :delete

FAQs

Package last updated on 17 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc