Sha256: f5eec8b76a82f2e7555a2d1392f1472ac7bc395263b27e98b9e3bd8457b012bc

Contents?: true

Size: 794 Bytes

Versions: 2

Compression:

Stored size: 794 Bytes

Contents

require 'sinatra/base'
require 'json'

require '../lib/sinatra/param'

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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sinatra-param-0.0.2 ./example/app.rb
sinatra-param-0.0.1 ./example/app.rb