Skip to content

Instantly share code, notes, and snippets.

@mkurtikov
Last active February 1, 2017 11:09
Show Gist options
  • Save mkurtikov/856bec55d7f85da469e9f3c08f56e173 to your computer and use it in GitHub Desktop.
Save mkurtikov/856bec55d7f85da469e9f3c08f56e173 to your computer and use it in GitHub Desktop.
sinatra_app
# To start the server please use
# shotgun config.ru to have life reload
# or rackup
# plase notice that in both cases we have different port
require 'sinatra'
require 'sinatra/param'
require 'sinatra/json'
class ImageParserApp < Sinatra::Application
before do
content_type 'application/json'
end
configure do
set :raise_sinatra_param_exceptions, true
set show_exceptions: false
end
post '/operations' do
param :image, String, required: true
param :operation, String, in: ['blur', 'contrast']
param :params, Hash
"Logic"
end
error Sinatra::Param::InvalidParameterError do
status 422
param_name = env['sinatra.error'].param
json( error: { param_name => 'param is invalid'})
end
end
require './app'
require 'rack/contrib'
use Rack::PostBodyContentTypeParser
run ImageParserApp
# A sample Gemfile
source "https://rubygems.org"
gem 'rack-contrib'
gem 'sinatra'
gem 'shotgun'
gem "sinatra-param", require: "sinatra/param"
gem 'sinatra-contrib'
GEM
remote: https://rubygems.org/
specs:
backports (3.6.8)
git-version-bump (0.15.1)
multi_json (1.12.1)
rack (1.6.4)
rack-contrib (1.4.0)
git-version-bump (~> 0.15)
rack (~> 1.4)
rack-protection (1.5.3)
rack
rack-test (0.6.3)
rack (>= 1.0)
shotgun (0.9.2)
rack (>= 1.0)
sinatra (1.4.7)
rack (~> 1.5)
rack-protection (~> 1.4)
tilt (>= 1.3, < 3)
sinatra-contrib (1.4.7)
backports (>= 2.0)
multi_json
rack-protection
rack-test
sinatra (~> 1.4.0)
tilt (>= 1.3, < 3)
sinatra-param (1.4.0)
sinatra (~> 1.3)
tilt (2.0.5)
PLATFORMS
ruby
DEPENDENCIES
rack-contrib
shotgun
sinatra
sinatra-contrib
sinatra-param
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment