Welcome to the pepper wiki! Pepper is a Ruby, DSL based framework for creating RESTful web applications. It adheres to the Ruby Rack specification.

Pepper treats every fragment in a URL as a “context”. Each context can be mapped to a block or another Pepper enabled module. For example, a URL of:

<pre>/users/1/images/1</pre>

could translate to a context block tree of:

<pre> <code> map ‘users’ do

map :digit do
  get{"The value of this user is #{value}"}
  map 'images' do
    map :digit do
      get{"The ID of this image is #{value}"}
    end
  end
end

end </code> </pre>

Because each block maps to a single url fragment, “routing” is not needed. The value of a context’s url fragment can be accessed by its :value attribute. You can also name the fragment and propagate to the request params like:

<pre> <code> map :user_id=>/d+/ do

puts params[:user_id]

end </code> </pre>

The :user_id param will then be available as a global request param to other contexts and “actions”.

The fragment value passed to :map can be a string, a regular expression or a symbol that matches one of the built-in rules; :digit, :word, etc.

Standard HTTP methods (GET, POST, PUT, etc.) are used as the “actions”. Each of the actions methods can accept a “rule” hash. The keys map to the REQUEST values (but down-cased and symbolized). So you could execute an action only if it matched the IP, or SERVER_NAME. The value of the rule can be a Regular Expression or a string.

Here is an example:

<pre> <code> require ‘pepper’

module SeriousApp

class Contact # A delegate/sub-app

  include Pepper::Context::Delegate

  build do
    before :post do
      # a before :post block. Default is :all.
    end

    get{'GET request'}
    post{'POST request'}

    # request for /contact/:word
    map :word do
      get{"GET request for /contact/#{value}"}
    end
  end
end

class Root

  include Pepper::App

  build do
    get{'A simple GET to /'}
    post{'A POST to /'}

    # /about/
    map 'about' do
      get{'GET request for /about'}
    end

    # /notes
    map 'notes' do
      get(:server_name=>/^myspecialdomain\.com$/) do
        'GET request for /notes, but only allowing a SERVER_NAME of "myspecialdomain.com"'}
      end
    end

    # forwarding /contact to the Contact class
    map 'contact', {}, Contact
  end

end

end </code> </pre>

You then instantiate the Root class, and pass it to Rack’s “run” method.

<pre> run SeriousApp::Root.new </pre>