Description
Very fast; "Sinatra-like" routes: support for get, post, put, patch, delete, options, head; Template rendering and caching through Tilt or ERB from stdlib; Set basic filters/callbacks with the before/after methods; Include middlewares with the use method; Mount rack apps with the map method; Sessions through Rack::Session; Halt execution at any point using Ruby's throw/catch mechanism; Thread-safe
Nancy alternatives and similar gems
Based on the "Web Frameworks" category.
Alternatively, view Nancy alternatives based on common mentions on social networks and blogs.
-
ReactOnRails
Integration of React + Webpack + Rails + rails/webpacker including server-side rendering of React, enabling a better developer experience and faster client performance. -
Glimmer DSL for Web
Glimmer DSL for Web (Ruby-in-the-Browser Web Frontend Framework). The "Rails" of Frontend Frameworks!!! -
Glimmer DSL for Opal
DISCONTINUED. Glimmer DSL for Opal (Pure-Ruby Web GUI and Auto-Webifier of Desktop Apps)
Scout Monitoring - Performance metrics and, now, Logs Management Monitoring with Scout Monitoring
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of Nancy or a related project?
Popular Comparisons
README
Nancy
Sinatra's little daughter
Description
Minimal Ruby microframework for web development inspired in Sinatra and Cuba
Installation
Install the gem:
$ gem install nancy
or add it to your Gemfile:
gem "nancy"
Usage
Here's a simple application:
# hello.rb
require "nancy"
require "nancy/render"
class Hello < Nancy::Base
use Rack::Session::Cookie, secret: ENV['SECRET_TOKEN'] # for sessions
include Nancy::Render
get "/" do
"Hello World"
end
get "/hello" do
response.redirect "/"
end
get "/hello/:name" do
"Hello #{params['name']}"
end
post "/hello" do
"Hello #{params['name']}"
end
get "/template" do
@message = "Hello world"
render("views/hello.erb")
end
post "/login" do
@user = User.find(params['username'])
halt 401, "unauthorized" unless @user.authenticate(params['password'])
session[:authenticated] = true
render("views/layout.erb") { render("views/welcome.erb") }
end
before do
if request.path_info == "/protected" && !session[:authenticated]
halt 401, "unauthorized"
end
end
get "/protected" do
"Protected area!!!"
end
after do
if request.path_info ~= /\.json$/
response['Content-Type'] = 'application/json'
else
response['Content-Type'] = 'text/html'
end
end
get "/users/:id.json" do
@user = User.find(params['id'])
halt 404 unless @user
UserSerializer.new(@user).to_json
end
map "/resque" do
run Resque::Server
end
map "/nancy" do
run AnotherNancyApp.new
end
end
To run it, you can create a config.ru
file:
# config.ru
require "./hello"
run Hello.new
You can now run rackup
and enjoy what you have just created.
Check examples folder for a detailed example.
Features
- Very fast
- "Sinatra-like" routes: support for get, post, put, patch, delete, options, head
- Template rendering and caching through Tilt or ERB from stdlib
- Set basic filters/callbacks with the before/after methods
- Include middlewares with the use method
- Mount rack apps with the map method
- Sessions through Rack::Session
- Halt execution at any point using Ruby's throw/catch mechanism
- Thread-safe
Version history
0.4.0 (unreleased)
- Added support for basic before/after filters
- Added Nancy::BasicRender for rendering of templates using
ERB
from stdlib - Refactored full code to set proper accessors for all methods
- Removed Nancy::Base.call, only instances can be used to run apps
- Removed redirect helper, use instead
response.redirect '/uri'
- Nancy::Render is not loaded automatically, "nancy/render" needs to be required
- Removed
tilt
dependency, to use Nancy::Render add it manually to app - Nancy::Base#halt can't be used with a
Rack::Response
object anymore
0.3.0 (Octuber 3, 2012)
- Removed unneccesary Thread accessors, use simple instance getters instead
- Refactored Nancy::Base#halt
0.2.0 (April 12, 2012)
- Set PATH INFO to '/' when is blank
- Fixed session method: Raise error when is used but Rack::Session isn't present
- Added support for HEAD and OPTIONS HTTP verbs
- Refactored Base.use to use a Rack::Builder internally
- Added Base.map to redirect requests to Rack sub-apps
0.1.0 (April 4, 2012)
- Created a new Github Page for the project
- Added env accessor, this add support for Shield
- Added support for templates caching using Tilt::Cache
- Moved render method from Nancy::Base to Nancy::Render module
- Refactored Nancy::Base to evaluate code blocks at instance level
- Fixed passing of render options to Tilt (thanks to lporras)
0.0.1 (March 20, 2012)
- Initial Release
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Copyright
Copyright (c) 2012-2014 Guillermo Iguaran. See LICENSE for further details.
*Note that all licence references and agreements mentioned in the Nancy README section above
are relevant to that project's source code only.