README.md in rack-app-0.14.0 vs README.md in rack-app-0.15.0
- old
+ new
@@ -1,9 +1,9 @@
# [Rack::App](http://rack-app.com/) [![Build Status][travis-image]][travis-link]
-[travis-image]: https://secure.travis-ci.org/adamluzsi/rack-app.rb.png?branch=master
-[travis-link]: http://travis-ci.org/adamluzsi/rack-app.rb
+[travis-image]: https://travis-ci.org/rack-app/rack-app.svg?branch=master
+[travis-link]: http://travis-ci.org/rack-app/rack-app
[travis-home]: http://travis-ci.org/
![Rack::App](http://rack-app-website.herokuapp.com/image/msruby_new.png)
Your next favourite rack based micro framework that is totally addition free!
@@ -37,33 +37,75 @@
$ gem install rack-app
## Usage
config.ru
+
+#### basic
+
```ruby
-require 'rack/app'
+require './bootstrap.rb'
-class YourAwesomeApp < Rack::App
+class App < Rack::App
+ desc 'some hello endpoint'
get '/hello' do
'Hello World!'
end
+end
+
+```
+
+#### complex
+
+```ruby
+
+require './bootstrap.rb'
+
+class App < Rack::App
+
+ mount SomeAppClass
+
+ headers 'Access-Control-Allow-Origin' => '*',
+ 'Access-Control-Expose-Headers' => 'X-My-Custom-Header, X-Another-Custom-Header'
+
+ serializer do |object|
+ object.to_s
+ end
+
+ desc 'some hello endpoint'
+ get '/hello' do
+ 'Hello World!'
+ end
+
+ desc 'some restful endpoint'
get '/users/:user_id' do
+ response.status = 201
params['user_id'] #=> restful parameter :user_id
- say #=> "hello world!"
- end
-
+ say #=> "hello world!"
+ end
+
+ desc 'some endpoint that has error and will be rescued'
+ get '/make_error' do
+ raise(StandardError,'error block rescued')
+ end
+
+
def say
- 'hello world!'
- end
-
-end
+ "hello #{params['user_id']}!"
+ end
-run YourAwesomeApp
+ error StandardError, NoMethodError do |ex|
+ {:error=>ex.message}
+ end
+ root '/hello'
+
+end
+
```
you can access Rack::Request with the request method and
Rack::Response as response method.
@@ -76,39 +118,55 @@
```ruby
require 'spec_helper'
require 'rack/app/test'
-describe MyRackApp do
+describe App do
include Rack::App::Test
-
+
rack_app described_class
-
- describe '#something' do
-
- subject{ get(url: '/hello', params: {'dog' => 'meat'}, headers: {'X-Cat' => 'fur'}) }
- it { expect(subject.body).to eq ['world']}
-
+ describe '/hello' do
+ # example for params and headers and payload use
+ subject{ get(url: '/hello', params: {'dog' => 'meat'}, headers: {'X-Cat' => 'fur'}, payload: 'some string') }
+
+ it { expect(subject.status).to eq 200 }
+
+ it { expect(subject.body.join).to eq "Hello World!" }
+ end
+
+ describe '/users/:user_id' do
+ # restful endpoint example
+ subject{ get(url: '/users/1234') }
+
+ it { expect(subject.body.join).to eq 'hello 1234!'}
+
it { expect(subject.status).to eq 201 }
-
- end
-
-end
+ end
+
+ describe '/make_error' do
+ # error handled example
+ subject{ get(url: '/make_error') }
+
+ it { expect(subject.body.join).to eq '{:error=>"error block rescued"}' }
+ end
+
+end
+
+
```
## Example Apps To start with
-* [Basic](https://github.com/adamluzsi/rack-app.rb-examples/tree/master/basic)
+* [Basic](https://github.com/rack-app/rack-app-example-basic)
* bare bone simple example app
-* [Escher Authorized Api](https://github.com/adamluzsi/rack-app.rb-examples/tree/master/escher_authorized)
+* [Escher Authorized Api](https://github.com/rack-app/rack-app-example-escher)
* complex authorization for corporal level api use
## [Benchmarking](https://github.com/adamluzsi/rack-app.rb-benchmark)
-
* Dump duration with zero business logic or routing: 2.4184169999892074e-06 s
* no routing
* return only a static array with static values
* Rack::App duration with routing lookup: 2.9978291999967683e-05 s