GithubHelp home page GithubHelp logo

rack-mount's Introduction

Rack::Mount

A stackable dynamic tree based Rack router.

Rack::Mount supports Rack’s X-Cascade convention to continue trying routes if the response returns pass. This allows multiple routes to be nested or stacked on top of each other. Since the application endpoint can trigger the router to continue matching, middleware can be used to add arbitrary conditions to any route. This allows you to route based on other request attributes, session information, or even data dynamically pulled from a database.

Usage

Rack::Mount provides a plugin API to build custom DSLs on top of.

The API is extremely minimal and only 3 methods are exposed as the public API.

Rack::Mount::RouteSet#add_route

builder method for adding routes to the set

Rack::Mount::RouteSet#call

Rack compatible recognition and dispatching method

Rack::Mount::RouteSet#generate

generates a route condition from identifiers or significant keys

Example

require 'rack/mount'

Routes = Rack::Mount::RouteSet.new do |set|
  # add_route takes a rack application and conditions to match with
  #
  # valid conditions methods are any method on Rack::Request
  # the values to match against may be strings or regexps
  #
  # See Rack::Mount::RouteSet#add_route for more options.
  set.add_route FooApp, { :request_method => 'GET', :path_info => %r{^/foo$} }, {}, :foo
end

# The route set itself is a simple rack app you mount
run Routes

# generate path for route named "foo"
Routes.generate(:path_info, :foo) #=> "/foo"

rack-mount's People

Contributors

josh avatar roman2k avatar pixeltrix avatar samuelkadolph avatar spastorino avatar aughr avatar ntalbott avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.