View on GitHub

web_pipe

One-way pipe rack application builder

Gem Version Build Status

WebPipe

web_pipe is a modular rack application builder through a pipe of operations on an immutable struct.

In order to use in conjunction with dry-rb ecosystem, see also dry-web-web_pipe.

  1. Introduction
  2. Design model
  3. Building a rack application
  4. Plugging operations
    1. Resolving operations
    2. Injecting operations
    3. Composing operations
  5. Using rack middlewares
    1. Injecting middlewares
    2. Composing middlewares
  6. Composing applications
  7. Connection struct
    1. Sharing data downstream
    2. Halting the pipe
    3. Configuring the connection struct
  8. DSL free usage
  9. Plugs
    1. Config
    2. ContentType
  10. Extensions
    1. Container
    2. Cookies
    3. Flash
    4. Dry Schema
    5. Dry View
    6. Params
    7. Redirect
    8. Router params
    9. Session
    10. URL
  11. Recipes
    1. dry-rb integration
    2. hanami-router integration
    3. Using all RESTful methods
# config.ru
require 'web_pipe'

WebPipe.load_extensions(:params)

class HelloApp
  include WebPipe
  
  AUTHORIZED_USERS = %w[Alice Joe]
  
  plug :html
  plug :authorize
  plug :greet
  
  private
  
  def html(conn)
    conn.add_response_header('Content-Type', 'text/html')
  end
  
  def authorize(conn)
    user = conn.params['user']
    if AUTHORIZED_USERS.include?(user)
      conn.add(:user, user)
    else
      conn.
        set_status(401).
        set_response_body('<h1>Not authorized</h1>').
        halt
    end
  end
  
  def greet(conn)
    conn.set_response_body("<h1>Hello #{conn.fetch(:user)}</h1>")
  end
end

run HelloApp.new

Current status

web_pipe is in active development. The very basic features to build a rack application are all available. However, very necessary conveniences to build a production application, for example a session mechanism, are still missing.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/waiting-for-dev/web_pipe.

Release Policy

web_pipe follows the principles of semantic versioning.