./README.md in sinatra-param-0.1.1 vs ./README.md in sinatra-param-0.1.2

- old
+ new

@@ -3,11 +3,11 @@ REST conventions takes the guesswork out of designing and consuming web APIs. `GET` / `POST` / `PATCH` / `DELETE` resource endpoints and you get what you'd expect. But figuring out what parameters are expected... well, all bets are off. This Sinatra extension takes a first step to solving this problem on the developer side -**`sinatra-param` allows you to declare, validate, and transform endpoint parameters as you would in frameworks like [DataMapper](http://datamapper.org/) or [ActiveModel](http://rubydoc.info/gems/activemodel/3.2.3/frames).** +**`sinatra-param` allows you to declare, validate, and transform endpoint parameters as you would in frameworks like [ActiveModel](http://rubydoc.info/gems/activemodel/3.2.3/frames) or [DataMapper](http://datamapper.org/).** ## Example ``` ruby require 'sinatra/param' @@ -15,26 +15,25 @@ helpers Sinatra::Param before do content_type :json end - + # GET /search?q=example # GET /search?q=example&categories=news # GET /search?q=example&sort=created_at&order=ASC get '/search' do param :q, String, required: true param :categories, Array param :sort, String, default: "title" param :order, String, in: ["ASC", "DESC"], transform: :upcase, default: "ASC" - + {...}.to_json end end ``` - ### Parameter Types By declaring parameter types, incoming parameters will automatically be transformed into an object of that type. For instance, if a param is `Boolean`, values of `'1'`, `'true'`, `'t'`, `'yes'`, and `'y'` will be automatically transformed into `true`. - `String` @@ -62,22 +61,18 @@ ## Next Steps - [Design by contract](http://en.wikipedia.org/wiki/Design_by_contract) like this is great for developers, and with a little meta-programming, it could probably be exposed to users as well. The self-documenting dream of [Hypermedia folks](http://twitter.com/#!/steveklabnik) could well be within reach. -- Another pain point is the awkward way parameters are passed as JSON in HTTP bodies. I'd love to see an elegant, unobtrusive way to do this automatically. - - Support for Rails-style Arrays (`'key[]=value1&key[]=value2'`) and Hashes (`'key[a]=value1&key[b]=value2`). /via [@manton](https://twitter.com/#!/manton) -- Testing. This will happen soon. - ## Contact Mattt Thompson - http://github.com/mattt - http://twitter.com/mattt - m@mattt.me ## License -sinatra-param is available under the MIT license. See the LICENSE file for more info. \ No newline at end of file +sinatra-param is available under the MIT license. See the LICENSE file for more info.