Project

rasti-web

0.0
Low commit activity in last 3 years
A long-lived project that still receives updates
Web blocks to build robust applications
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.0
~> 13.0
~> 0.8
~> 5.0, < 5.11
~> 0.6
~> 0.12

Runtime

 Project Readme

Rasti::Web

Gem Version CI Coverage Status Code Climate

Web blocks to build robust applications

Installation

Add this line to your application's Gemfile:

gem 'rasti-web'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rasti-web

Usage

Routing

# app.rb
class WebApp < Rasti::Web::Application

  use SomeMiddleware

  get '/hello' do |request, response, render|
    render.text 'world'
  end

  put '/users/:id', UsersController >> :update

end

# configu.ru
require_relative 'app'
run WebApp

Controllers

class UsersController < Rasti::Web::Controller

  def update
    user = User.find(params[:id])
    if user.update_attributes(params[:user])
      render.view 'users/list', users: User.all
    else
      render.view 'users/edit', user: user
    end
  end

end

Hooks

class UsersController < Rasti::Web::Controller

  before_action do |action_name|
  end

  before_action :action_name do
  end

  after_action do |action_name|
  end

  after_action :action_name do
  end

end

Error handling

class UsersController < Rasti::Web::Controller

  rescue_from StandardError do |ex|
    render.status 500, 'Unexpected error'
  end

end

Contributing

  1. Fork it ( https://github.com/gabynaiman/rasti-web/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request