Skip to content

waiting-for-dev/web_pipe

Repository files navigation

Gem Version Build Status

WebPipe

web_pipe is a builder of composable rack applications through a pipe of functions on an immutable struct.

web_pipe plays incredibly well with hanami 2. If you want to create a hanami 2 app with web_pipe, you can take inspiration from this sample todo application:

https://github.com/waiting-for-dev/hanami_2_web_pipe_todo_app

  1. Introduction
  2. Design model
  3. Building a rack application
  4. Plugging operations
    1. Resolving operations
    2. Injecting operations
    3. Composing operations
    4. Inspecting operations
  5. Using rack middlewares
    1. Injecting middlewares
    2. Composing middlewares
    3. Inspecting middlewares
  6. Composing applications
  7. Connection struct
    1. Sharing data downstream
    2. Halting the pipe
    3. Configuring the connection struct
  8. Overriding instance methods
  9. DSL free usage
  10. Plugs
    1. Config
    2. ContentType
  11. Testing
  12. Extensions
    1. Container
    2. Cookies
    3. Flash
    4. Dry Schema
    5. Hanami View
    6. Not found
    7. Params
    8. Rails
    9. Redirect
    10. Router params
    11. Session
    12. URL
  13. Recipes
    1. hanami 2 & dry-rb integration
    2. Injecting dependencies through dry-auto_inject
    3. hanami-router integration
    4. 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 but ready to be used in any environment. Everyday needs are covered, and while you can expect some API changes, they won't be essential, and we'll document everything appropriately.

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.

About

One-way pipe, composable, rack application builder

Topics

Resources

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published