Skip to content

Kenji Integration: declare input validations declaratively vs. run them as code #6

@kballenegger

Description

@kballenegger

Crazy idea:

In Kenji, an input validation might be written declaratively, above the route, instead of as code within the route.

Code could look like this:

validate! do
  # symbols are path params
  validates_type_of :id, is: Blah
  # string are body keys
  validates_type_of 'name', is: String
end
post '/friends/:id' do 
  # method body
end

Or:

post '/friends/:id',
  validate: -> {
    # symbols are path params
    validates_type_of :id, is: Blah
    # string are body keys
    validates_type_of 'name', is: String
  } do
  # method body
end

Here, we gain the ability to:

  1. validate path params, and passed vars, instead of only body
  2. run validations only with no additional code (magic VALIDATE http method)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions