Sha256: 53b298673fd7ab4d772a4815a408433fa2aaa9448625a3b15381502bd43a7fd8
Contents?: true
Size: 739 Bytes
Versions: 1
Compression:
Stored size: 739 Bytes
Contents
require 'sinatra/base' require 'compel' class SinatraApp < Sinatra::Base set :show_exceptions, false set :raise_errors, true before do content_type :json end helpers do def compel(schema) params.merge! Compel.run!(params, Compel.hash.keys(schema)) end end error Compel::InvalidHashError do |exception| status 400 { errors: exception.errors }.to_json end configure :development do set :show_exceptions, false set :raise_errors, true end post '/api/posts' do compel({ post: Compel.hash.keys({ title: Compel.string.required, body: Compel.string, published: Compel.boolean.default(false) }).required }) params.to_json end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
compel-0.2.0 | spec/support/sinatra_app.rb |