Created
April 14, 2016 15:47
-
-
Save mkurtikov/8a4cfd9409bd88c88800bd513f105c60 to your computer and use it in GitHub Desktop.
Sinatra Basics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'sinatra' | |
| require 'sinatra/param' | |
| require 'sinatra/json' | |
| set :raise_sinatra_param_exceptions, true | |
| set :show_exceptions, false | |
| get '/hi' do | |
| param :param1, Float, required: true | |
| param :param2, Float, required: true | |
| param :operation, String, in: ['plus', 'minus'] | |
| result = params['param1'] + params['param2'] | |
| json({ calculation: { result: result } }) | |
| end | |
| error Sinatra::Param::InvalidParameterError do | |
| status 422 | |
| { error: "#{env['sinatra.error'].param} is invalid" }.to_s | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment