File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -192,6 +192,26 @@ post '/json_endpoint' do
192192end
193193```
194194
195+ ## Validations
196+
197+ You can define validations and coercion option for your attributes:
198+
199+ ``` ruby
200+ params do
201+ required :id , type: Integer
202+ optional :name , type: String , regexp: /^[a-z] +$/
203+ end
204+
205+ get ' :id' do
206+ # params[:id] is an Integer
207+ end
208+ ```
209+
210+ The coercion is handled by the really nice Virtus gem which will convert the value if possible but
211+ in case of invalid input nothing will be done (ex: asking to coerce "ex" to Integer will return "ex" ).
212+ Proper type validation could be added later when Virtus will get a way to tell us.
213+
214+
195215## Headers
196216
197217Headers are available through the ` env ` hash object.
You can’t perform that action at this time.
0 commit comments