# [Rack::App](http://rack-app.com/) [![Build Status][travis-image]][travis-link] [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_old.png) Your next favourite rack based micro framework that is totally addition free! Have a cup of awesomeness with your performance designed framework! The idea behind is simple. Keep the dependencies and everything as little as possible, while able to write pure rack apps, that will do nothing more than what you defined. If you want see fancy magic, you are in a bad place buddy! This includes that it do not have such core extensions like activesupport that monkey patch the whole world. Routing can handle any amount of endpoints that can fit in the memory, so if you that crazy to use more than 10k endpoint, you still dont have to worry about response speed. It was inspirited by sinatra, grape, and the pure use form of rack. It's in production, powering Back Ends on Heroku ## Installation Add this line to your application's Gemfile: ```ruby gem 'rack-app' ``` And then execute: $ bundle Or install it yourself as: $ gem install rack-app ## Is it Production ready? Yes, in fact it's already powering heroku hosted micro-services. ## Usage config.ru #### basic ```ruby require 'rack/app' class App < Rack::App desc 'some hello endpoint' get '/hello' do 'Hello World!' end end ``` #### complex ```ruby require 'rack/app' 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 return 'Hello World!' end namespace '/users' do desc 'some restful endpoint' get '/:user_id' do response.status = 201 params['user_id'] #=> restful parameter :user_id say #=> "hello world!" end end desc 'some endpoint that has error and will be rescued' get '/make_error' do raise(StandardError,'error block rescued') end def say "hello #{params['user_id']}!" end 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. By default if you dont write anything to the response 'body' the endpoint block logic return will be used ## Testing for testing use rack/test or the bundled testing module for writing unit test for your rack application ```ruby require 'spec_helper' require 'rack/app/test' describe App do include Rack::App::Test rack_app described_class 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 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/rack-app/rack-app-example-basic) * bare bone simple example app * [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) RackSkeleton avg duration: 5.2298899999950066e-06 s Rack::App avg duration: 3.323366999999523e-05 s Grape::API avg duration: 0.00031554329000000426 s Rack::App 9.494686864256929x faster (0.000282309620000009 sec) that Grape::API RackSkeleton 6.354563862725021x faster (2.800378000000022e-05 sec) that Rack::App RackSkeleton 60.33459403549703x faster (0.00031031340000000924 sec) than Grape::API To be honest, I measured with grape because that is one of my favorite micro framework! ## Roadmap ### Team [Backlog](https://docs.google.com/spreadsheets/d/19GGX51i6uCQQz8pQ-lvsIxu43huKCX-eC1526-RL3YA/edit?usp=sharing) If you have anything to say, you can leave a comment. :) ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/adamluzsi/rack-app.rb This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.