- Notifications
You must be signed in to change notification settings - Fork0
A lightning-fast, batteries-included Ruby web micro-framework.
License
joshmn/jeanine
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A Ruby micro-web-framework that gives you enough training wheels to be productive, while being as nearly as fast as Rack itself.
Its design (and some parts of the code) is influenced by/inherited from (thanks!) Ruby on Rails, Rack::App, Hobbit, and Cuba. Without them this is nothing.
Named after my mom. Because she was the best.
Add this line to your application's Gemfile:
gem'jeanine'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install jeanine
Drop this intoconfig.ru
:
require'bundler/setup'require'jeanine'classApp <Jeanine::Approotdo"Hello world"endendrunApp
$ rackup
Or generate a new app:
$ gem install jeanine$ jeanine new my_api$ cd my_api$ bundle$ rackup
classApp <Jeanine::Apppath"/posts"dogetdoifrequest.json?renderjson:[]else"Posts index"endendget"new"do"Posts new"endpostdo"Posts post"endpath":id"dogetdo"Posts#{params[:id]}"endmatchvia:[:put,:patch]do"Posts#{request.via}#{params[:id]}"enddeletedo"Posts delete#{params[:id]}"endpath"/comments"dogetdo"Posts#{params[:id]} comments"endendendendend
Supportsbefore
andafter
callbacks (same DSL):
classApp <Jeanine::Appplugin:Callbacksbeforedoputs"All"endbefore/posts/doputs"Before posts"endbefore/posts\/\d*/,/comments\/\d*/doputs"Before posts/:id, comments/:id"response.headers['X-Thing-Id']=params[:id]endend
Basic support for rendering. Be explicit.
classApp <Jeanine::Appplugin:Rendering# loads views/root.html.erb and views/layouts/application.html.erbrootdo@title="My cool app"rendertemplate:"root.html.erb",layout:"application.html.erb"endend
Uses Rack's session management.
classApp <Jeanine::Appplugin:Sessionrootdosession[:uid]=SecureRandom.hexendend
classApp <Jeanine::Appplugin:Rescuablerescue_fromNoMethodError,RuntimeErrordo |exception|response.status=500"Oh no!"endrescue_fromStandardError,with::handle_error!rootdo@title="My cool app"raiseNoMethodErrorrendertemplate:"root.html.erb",layout:"application.html.erb"endprivatedefhandle_error!(exception)response.status=500rendertemplate:"error.html.erb"endend
- No meaningless metaprogramming = fast
Benched on a Intel Core i7-8700B / 64GB RAM.
Framework Requests/sec % from best----------------------------------------------rack 17299.31 100.00%jeanine 16022.71 92.62%rack-response 15462.50 89.38%syro 15416.13 89.11%watts 15307.52 88.49%roda 14550.56 84.11%hanami-router 14342.92 82.91%cuba 14246.23 82.35%hobbit 14132.20 81.69%rambutan 12526.40 72.41%rack-app 11696.66 67.61%flame 7931.61 45.85%rails-metal 7761.75 44.87%sinatra 4616.81 26.69%grape 2401.66 13.88%hobby 1805.93 10.44%rails-api 1593.77 9.21%
Framework Allocs/Req Memsize/Req--------------------------------------rack 40 3408roda 43 4016syro 44 4288cuba 44 4056watts 46 3648hobbit 48 4416jeanine 52 4576hobby 52 5416rack-response 55 5128rails-metal 59 5848hanami-router 63 5184rambutan 79 6944rack-app 80 8424flame 115 9648sinatra 179 13440grape 250 26704rails-api 383 34949
- Callback constraints
- File downloads
Bug reports and pull requests are welcome on GitHub athttps://github.com/joshmn/jeanine.
The gem is available as open source under the terms of theMIT License.
About
A lightning-fast, batteries-included Ruby web micro-framework.