0.0
No commit activity in last 3 years
No release in over 3 years
Web application request handlers.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.10
>= 10.0

Runtime

 Project Readme

Spine::Actions

Gem Version Dependency Status Code Climate security Inline docs

HTTP endpoint action with before and after callbacks, response builder.

Installation

To install it, add the gem to your Gemfile:

gem 'spine-actions'

Then run bundle. If you're not using Bundler, just gem install spine-actions.

Usage

Each action can access Rack env, request and response.

Action provides following methods to respond: respond(content, options), redirect(url, options) and send_data(binary, options). Options include :status, :content_type, :data and :filename.

Response headers can be set using response['header-name'] = 'value' before running response.

class Status < Spine::Actions::Action
  before :authenticate
  after :close_connections

  # It will be used as response type. Default is Spine::ContentTypes::Html
  def format
    Spine::ContentTypes::Json
  end

  def action
    # ...
    respond({ status: 'OK' }, status: 200)
  end

  def authenticate
    # ...
  end

  def close_connections
    # ...
  end
end


Status.call(env)

Using with default Rack routing

# config.ru

map 'status' do
  run Status
end

Using with Spine::Routing

# config.ru

router = Spine::Routing::Router.new
router.configure do
  get :status, to: Status
end

run router