rack-middleware

Implement and manage Rack middleware for Ruby web applications.

8|2|Updated Oct 17, 2025
One-click install
npx skills add https://github.com/geoffjay/claude-plugins --skill rack-middleware
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rack-middleware
Source: https://github.com/geoffjay/claude-plugins/tree/main/plugins/ruby-sinatra-advanced/skills/rack-middleware
Command: npx skills add https://github.com/geoffjay/claude-plugins --skill rack-middleware

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires redis, rack-attack, rack-cors, rack-ssl, rack-protection, and includes assets (resource) and references (resource) components.

What problem does it solve?

Effectively extending and customizing Ruby web applications (like Sinatra or Rails) often involves working with Rack middleware. Understanding how to develop, configure, and order middleware is crucial for building robust and performant applications.

Core Features & Use Cases

  • Middleware Structure: Learn the basic initialize and call methods for creating custom Rack middleware, forming the foundation of your web stack.
  • Custom Middleware Development: Step-by-step examples for building request logging, token authentication, caching, and request transformation middleware to extend functionality.
  • Middleware Ordering Patterns: Guidance on structuring middleware stacks for security-first or API-focused applications, and using conditional middleware for flexible deployment.
  • Use Case: A developer needs to add custom logging and authentication to their Sinatra application without modifying the core application logic. This Skill provides detailed examples for creating RequestLogger and TokenAuthentication middleware, showing how to integrate them into the Rack stack and ensure proper ordering.

Quick Start

Basic Rack middleware structure

class MyMiddleware def initialize(app, options = {}) @app = app @options = options end

def call(env) # Before request status, headers, body = @app.call(env) # After request [status, headers, body] end end

Usage in config.ru

use MyMiddleware, option: 'value'

Frequently Asked Questions about rack-middleware

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I build custom Rack middleware for my Ruby web application?

Custom Rack middleware extends HTTP request/response cycles by implementing `initialize(app, options)` and `call(env)` methods. Create a class that wraps your app, processes requests before passing to `@app.call(env)`, and modifies responses after. Register it in config.ru using `use MyMiddleware` to integrate into your Rack stack.

What's the best way to handle authentication and logging across a Sinatra or Rails application?

Middleware handles cross-cutting concerns like authentication and logging without modifying core logic. Build specialized middleware classes for token validation and request logging, order them in config.ru to ensure security checks run first, and configure skip_paths for routes that bypass certain middleware.

How do I order middleware in my Rack stack for security and performance?

Middleware ordering matters: place security middleware like SSL and authentication near the top, logging and caching in the middle, and compression last. The stack executes top-to-bottom on requests and bottom-to-top on responses. Use conditional middleware to skip processing for specific paths or request types.

Can I use middleware to handle caching, compression, and session management in Rack-based apps?

Yes, middleware is designed for cross-cutting concerns including caching, compression, and session management. Each concern becomes a separate middleware class that intercepts the request/response cycle. Combine multiple middleware in config.ru to build a complete HTTP processing pipeline for Sinatra and Rails.

What middleware dependencies like rack-attack or rack-cors do and how do they integrate?

Rack ecosystem middleware like rack-attack, rack-cors, rack-ssl, and rack-protection provide rate limiting, CORS handling, SSL enforcement, and security headers. Each follows the standard Rack interface and integrates by adding `use` directives in config.ru, composing them into your application's middleware stack.