New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mwmitchell-pepper

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mwmitchell-pepper

  • 0.3.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

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:

/users/1/images/1

could translate to a context block tree of:


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

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:


map :user_id=>/\d+/ do
  puts params[:user_id]
end

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:


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

You then instantiate the Root class, and pass it to Rack's "run" method.


run SeriousApp::Root.new

FAQs

Package last updated on 11 Aug 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc