Sha256: 24032a2ffe22f108d3e58b1ec8eb7632637579e2ce22a8930b1b3ef57743d6df

Contents?: true

Size: 924 Bytes

Versions: 17

Compression:

Stored size: 924 Bytes

Contents

class App < Sinatra::Base
  helpers Sinatra::Param

  before do
    content_type :json
  end

  # GET /messages
  # GET /messages?sort=name&order=ASC
  get '/messages' do
    param :sort,  String, default: "name"
    param :order, String, in: ["ASC", "DESC"], transform: :upcase, default: "ASC"

    {
      sort: params[:sort],
      order: params[:order]
    }.to_json
  end

  # GET /messages/1,2,3,4,5
  get '/messages/:ids' do
    param :ids, Array, required: true

    {
      ids: params[:ids]
    }.to_json
  end

  # POST /messages/1/response
  post '/messages/:id/response' do
    param :message, String, max: 1024, required: true

    {
      message: params[:message]
    }.to_json
  end

  # GET /choice?a=foo
  # GET /choice?b=bar
  # GET /choice?c=baz
  get '/choice' do
    param :a, String
    param :b, String
    param :c, String

    one_of(:a, :b, :c)

    {
      message: 'OK'
    }.to_json
  end
end

Version data entries

17 entries across 17 versions & 3 rubygems

Version Path
jdx-sinatra-param-0.0.1 ./example/app.rb
sinatra-param-1.6.0 ./example/app.rb
sinatra-param-1.5.0 ./example/app.rb
sinatra-param2-1.0.0 ./example/app.rb
sinatra-param-1.4.0 ./example/app.rb
sinatra-param-1.3.1 ./example/app.rb
sinatra-param-1.3.0 ./example/app.rb
sinatra-param-1.2.2 ./example/app.rb
sinatra-param-1.2.1 ./example/app.rb
sinatra-param-1.2.0 ./example/app.rb
sinatra-param-1.1.2 ./example/app.rb
sinatra-param-1.1.1 ./example/app.rb
sinatra-param-1.1.0 ./example/app.rb
sinatra-param-1.0.3 ./example/app.rb
sinatra-param-1.0.2 ./example/app.rb
sinatra-param-1.0.1 ./example/app.rb
sinatra-param-1.0.0 ./example/app.rb