Skip to content

Strong type declarations for the parameters accepted by your API endpoints.

License

Notifications You must be signed in to change notification settings

zipmark/typed_params

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TypedParams

The purpose of typed_params is to declare and enforce type constraints on your Rails API endpoints.

NOTE: We use 'parameter' and 'attribute' somewhat interchangably, as this is the same convention used by Rails (notice the usage of the two words throughout that documentation).

Usage

Imagine you have a Foo model/resource, and a FoosController. You want to enforce a certain params structure for requests to foos#create.

class FoosController < ActionController::API
  # enforce json-api format
  CreateFooParams = {
    data: {
      attributes: {
        name:  String,
        email: String
      }
    }
  }

  assert_params_format CreateFooParams, on: :create

  def create
    # If you reach this line, then the request body adheres to the type
    # declarations of CreateFooParams. Proceed with confidence!
  end
end

License

The gem is available as open source under the terms of the MIT License.

About

Strong type declarations for the parameters accepted by your API endpoints.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published