Request Lifecycle

Understanding Jetpath's request lifecycle is essential for building efficient and maintainable applications. This document outlines the complete journey of a request from arrival to response.

Request Lifecycle

1. Route Matching

When a request arrives:

2. Context Creation

A Context object is created or reused from the context pool:

3. Pre-Handler Middleware

Before reaching the route handler, the request passes through middleware pre-handlers:

4. Route Handler Execution

The matched route handler runs:

5. Post-Handler Middleware

After the handler completes (or throws), post-handlers run in reverse order:

6. Response

The response is sent to the client:

Error Flow

If an error occurs at any stage:

  1. The error is caught by Jetpath's internal handler
  2. All collected post-handler middleware functions are called with the error
  3. If no middleware handles it, a generic 500 response is sent
  4. The context is still returned to the pool

Performance Notes