Wouter

Wouter is a modular web framework built on top of Rack.

Wouter design goals: explicit, modular, readable.

Quick Example

Wouter allows you to define routes that connect to endpoints.

Here is an example rackup compatible config.ru:

require 'wouter'

class HelloWorld < Wouter::Endpoint
  def respond
    'Hello, world!'
  end
end

class Routes < Wouter
  get '/', HelloWorld
end

run Routes.build

Wouter builds routes to dispatch requests to Wouter::Endpoint instances.

An example application can be viewed here.

Instances of Wouter

When you create an instance of the Wouter class, you must call .build to create the Rack application.

Wouter DSL

HTTP routes:

  • get
  • put
  • post
  • delete

Rack middleware:

  • middleware - add Rack middleware

Instaces of Wouter::Endpoint

Instances of Wouter::Endpoint have access to a few helper methods.

  • req - an instance of Rack::Request for the current HTTP request
  • res - an instance of Rack::Response for the current HTTP response
  • params - convience method for access to req.params and any URL route parameters
  • headers - convience method for getting and setting HTTP headers
  • status - get or set HTTP status code
  • not_found - generates a HTTP 404 Not Found Rack::Response

Extensions

  • wouter-views - View template support for Wouter web framework