Request-Response Lifecycle - Hooks & Middleware Chain

Manage web framework request-response lifecycles with chainable hooks.

115|8|Updated Mar 30, 2025
One-click install
npx skills add https://github.com/Goldziher/spikard --skill request-response-lifecycle-hooks-middleware-chain
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Request-Response Lifecycle - Hooks & Middleware Chain
Source: https://github.com/Goldziher/spikard/tree/main/.ai-rulez/skills/request-response-lifecycle
Command: npx skills add https://github.com/Goldziher/spikard --skill request-response-lifecycle-hooks-middleware-chain

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill allows developers to intercept and modify requests and responses at various stages of the HTTP lifecycle, enabling custom logic for cross-cutting concerns without altering core handler code.

Core Features & Use Cases

  • Extensible Lifecycle: Provides five key hook points: onRequest, preValidation, preHandler, onResponse, and onError.
  • Custom Logic Injection: Implement logging, authentication, data transformation, error handling, and more.
  • Use Case: Automatically log every incoming request's method and path, enrich responses with a calculated duration, and standardize error responses before they are sent to the client.

Quick Start

Register an onRequest hook to log the incoming request method and path.

Frequently Asked Questions about Request-Response Lifecycle - Hooks & Middleware Chain

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

FAQPage Schema
How do I inject custom logic into the HTTP request lifecycle without altering core handler code?

You can inject custom logic into the HTTP request lifecycle by using a chainable system of hooks to intercept and modify requests and responses at various stages, handling cross-cutting concerns without changing the core handler.

What hook points are available for HTTP request and response handling?

Available HTTP request and response handling hook points include onRequest, preValidation, preHandler, onResponse, and onError, allowing developers to manage tasks like logging, authentication, and response transformation.

Can I use asynchronous operations within middleware hooks for API request processing?

Yes, you can use asynchronous operations within middleware hooks for API request processing, as the system supports asynchronous execution and request-scoped state management via extensions.

What's the best way to standardize API error responses before they reach the client?

The best way to standardize API error responses is to register an onError hook to intercept errors during the request-response lifecycle and format the output consistently before it is sent to the client.

How do I automatically log incoming HTTP request methods and paths?

To automatically log incoming HTTP request methods and paths, register an onRequest hook at the start of the request-response lifecycle to execute your logging logic before further processing.

Does this middleware chain approach support request-scoped state management?

Yes, this middleware chain approach supports request-scoped state management by utilizing extensions, allowing you to maintain and pass state across different hook points during the HTTP lifecycle.