sinatra-param
sinatra-param copied to clipboard
Boolean type parameter not working
If I try
patch '/:id' do |id|
content_type :json
param :foo, Boolean, required: true
end
And try to do a patch passing as body:
{
"foo": true
}
It raises 400 error. Am I doing anything wrong?
It doesn't decode JSON by default. Just query parameters and application/x-www-form-urlencoded in body.
From the README:
Use sinatra-param in combination with Rack::PostBodyContentTypeParser and Rack::NestedParams to automatically parameterize JSON POST bodies and nested parameters.
Sorry, I haven't tried that. There is another Issue asking for particulars. https://github.com/mattt/sinatra-param/issues/89
You should go visit the documentation for Rack::PostBodyContentTypeParser and Rack::NestedParams.
I gather that Rack::PostBodyContentTypeParser reads JSON body and adds to params.