middleware v0.1.0

Middleware

GitHub release Build Status

Middleware

Middleware is a library which provides a generalized implementation of the chain of responsibility pattern for Crystal.

This is heavily based on HTTP stdlib and inspiration from https://github.com/Ibsciss/ruby-middleware

Installation

Add this to your application's shard.yml:

dependencies:
  middleware:
    github: russ/middleware

Usage

require "middleware"
class PushHandler
  include Middleware::Handler(String)

  def initialize(@to_add : String)
  end

  def call(env : EnvType) : String
    env["result"] << @to_add
    call_next(env)
  end
end

context = { "result" => [] of String }
instance = Middleware::Builder.new([
  PushHandler.new("foobar"),
  PushHandler.new("barfoo")
] of Middleware::Handler(String))
instance.call(context)

{ "result" => ["foobar", "barfoo"] }

Contributing

  1. Fork it ( https://github.com/russ/Middleware/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

Contributors

  • russ Russ Smith - creator, maintainer
Repository

middleware

Owner
Statistic
  • 0
  • 1
  • 0
  • 0
  • 0
  • almost 2 years ago
  • May 11, 2018
License

MIT License

Links
Synced at

Sun, 19 May 2024 18:48:16 GMT

Languages