Sha256: e6edb4fa9c3656711c072dee3e85fdbc3557dbfd9f12f872c21e3f40a8cd1c12

Contents?: true

Size: 467 Bytes

Versions: 1

Compression:

Stored size: 467 Bytes

Contents

require 'json'
require 'sinatra/base'
require 'sinatra/param_checker'

class BookApp < Sinatra::Base
  register Sinatra::ParamChecker

  params '/books', methods: [:post] do
    required 'name', type: String
    optional 'author', type: String, default: 'unknown'
    required 'publish_date', type: Date
  end
  post '/books' do
    {
      name: params[:name],
      author: params[:author],
      publish_date: params[:publish_date]
    }.to_json
  end

  run!
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sinatra_param_checker-0.1.0 examples/book_app.rb