VOOZH about

URL: https://deepwiki.com/hypervel/components/3.1-request-lifecycle-and-processing

⇱ Request Lifecycle and Processing | hypervel/components | DeepWiki


Loading...
Last indexed: 7 March 2026 (96fbab)
Menu

Request Lifecycle and Processing

This document describes how HTTP requests are received, processed, and made available to application code in Hypervel. It covers the Request class, coroutine-safe context isolation, input retrieval methods, and integration with validation, sessions, and authentication systems.

For information about routing and dispatching requests to handlers, see Routing and Dispatching. For middleware execution, see Middleware Pipeline. For URL generation, see URL Generation and Signed URLs.

Overview

Hypervel's request handling is built on top of Hyperf's HTTP server and provides a Laravel-compatible API for accessing request data. The Request class (src/http/src/Request.php) extends Hyperf's base request class and adds extensive functionality for input retrieval, validation, session integration, and content negotiation. All request data is stored in coroutine-safe Context storage to ensure proper isolation in concurrent environments.

Request Object Architecture

The Request class implements the RequestContract interface and extends Hyperf's Request class, providing both PSR-7 compatibility and Laravel-style convenience methods.


Sources: src/http/src/Request.php31 src/http/src/Contracts/RequestContract.php18 src/support/src/Facades/Request.php144 src/foundation/src/Application.php597-601

Request Lifecycle

The following diagram illustrates the complete lifecycle of an HTTP request from reception to handler execution:


Sources: src/http/src/Request.php971-984 src/foundation/src/Application.php597-607

Context-Based Request Isolation

Hypervel uses Hyperf's Context storage to maintain request isolation across coroutines. Each concurrent request operates in its own coroutine with independent context storage.

Context Storage Keys

The Request class stores data in specific context keys:

Context KeyContentPurpose
ServerRequestInterface::classPSR-7 request objectBase request data
http.request.parsedDataParsed input arrayCombined query, body, and file data
RequestContextCurrent request instanceRequest context helper access

Retrieving the PSR-7 Request

The Request class retrieves the underlying PSR-7 request from context storage:


Sources: src/http/src/Request.php971-984

Context Manipulation Methods

The Request class provides methods to modify context data:

These methods modify the http.request.parsedData context key to ensure changes are visible within the current coroutine.

Sources: src/http/src/Request.php335-372

Input Retrieval Methods

The Request class provides extensive methods for accessing input data with type conversion and validation.

Basic Input Access

MethodReturn TypeDescription
input($key, $default)mixedGet input value with optional default
query($key, $default)mixedGet query string parameter
post($key, $default)mixedGet POST body parameter
all($keys)arrayGet all input (including files)
only($keys)arrayGet only specified keys
except($keys)arrayGet all except specified keys

Sources: src/http/src/Request.php407-422 src/http/src/Request.php387-402 src/http/src/Request.php140-148

Type-Safe Input Retrieval

The Request class provides type-casting methods for safe input handling:


Implementation details:

Sources: src/http/src/Request.php74-133 src/http/src/Request.php177-188 src/http/src/Request.php278-281

Input Presence and Validation Checks

The Request class provides methods to check input presence and emptiness:

Presence Check Methods

MethodBehaviorUse Case
has($keys)Key exists (inherited from Hyperf)Check if input was sent
exists($keys)Alias of has()Laravel compatibility
missing($keys)Inverse of has()Check if input was not sent
filled($keys)Key exists and non-emptyValidate required fields
isNotFilled($keys)Key missing or emptyCheck for empty values
anyFilled($keys)At least one key is filledOR validation
hasAny($keys)At least one key existsOR presence check

Empty String Detection

The isEmptyString() method determines if a value is considered empty for the filled() check:


Sources: src/http/src/Request.php286-293 src/http/src/Request.php161-172 src/http/src/Request.php306-317 src/http/src/Request.php56-67

Conditional Processing

The Request class provides fluent conditional methods:

Sources: src/http/src/Request.php152-380

File Upload Handling

File uploads are accessed through PSR-7 UploadedFileInterface instances:

  • allFiles() - Returns all uploaded files from getUploadedFiles() (src/http/src/Request.php48-51)
  • file($key) - Inherited from Hyperf, retrieves specific file
  • hasFile($key) - Inherited from Hyperf, checks if file was uploaded

Files are merged with regular input in the all() method using array_replace_recursive() (src/http/src/Request.php407-422).

Sources: src/http/src/Request.php48-51 src/http/src/Request.php407-422

Request Introspection

URL and Path Methods

The Request class provides comprehensive URL introspection:

MethodReturnsExample
url()Base URL without queryhttp://example.com/path
fullUrl()URL with query stringhttp://example.com/path?foo=bar
root()Scheme and hosthttps://example.com:8080
path()URL path/path/to/resource
segments()Path segments array['path', 'to', 'resource']
segment($index)Specific segment (1-indexed)segment(1) returns 'path'

Advanced URL methods:

Sources: src/http/src/Request.php615-660 src/http/src/Request.php672-687 src/http/src/Request.php748-751

Route Information

The Request class integrates with the routing system:


Route methods:

Sources: src/http/src/Request.php664-667 src/http/src/Request.php694-735

HTTP Method and Headers

Host and scheme information:

Sources: src/http/src/Request.php214-273 src/http/src/Request.php430-441

Client Information

Sources: src/http/src/Request.php591-612 src/http/src/Request.php740-743 src/http/src/Request.php764-777

Content Negotiation

The Request class provides extensive content negotiation support for REST APIs:

Accept Header Processing


Content negotiation methods:

Sources: src/http/src/Request.php446-547

Request Type Detection

Sources: src/http/src/Request.php298-301 src/http/src/Request.php817-864

MIME Type Mapping

Sources: src/http/src/Request.php784-807

Session Integration

The Request class provides seamless session access:

Session Methods

The session is resolved from the application container using the SessionContract::class binding. This ensures the correct session instance is retrieved for the current coroutine context.

Sources: src/http/src/Request.php869-882

Validation Integration

The Request class provides direct validation support:

Inline Validation


Validation method:


This method:

  1. Retrieves the validator factory from the container
  2. Validates $this->all() against the provided rules
  3. Returns validated data on success
  4. Throws ValidationException on failure

Sources: src/http/src/Request.php889-894

Authentication Integration

The Request class supports authentication through a user resolver callback:

User Resolution


Authentication methods:

The user resolver is typically set by the authentication middleware to integrate with the Auth system. The callback receives an optional guard name and returns the authenticated user model or null.

Sources: src/http/src/Request.php899-921

Signed URL Verification

The Request class integrates with the URL generator for signed URL validation:

Signature Verification Methods

All signature methods delegate to the UrlGenerator which is resolved from the container. This enables middleware and controllers to easily verify that URLs haven't been tampered with.

Sources: src/http/src/Request.php926-961

Request Facade and Helper

The Request can be accessed through multiple mechanisms:

Access Methods

MethodUsageResolution
Dependency Injectionfunction (Request $request)Container resolves RequestContract
FacadeRequest::input('key')Static proxy to container instance
Helper functionrequest('key')Returns Request instance or value
Containerapp('request')Direct container resolution

Container Aliases:

The Application container registers multiple aliases for the Request (src/foundation/src/Application.php597-607):

  • request
  • Psr\Http\Message\ServerRequestInterface
  • Hyperf\HttpServer\Contract\RequestInterface
  • Hyperf\HttpServer\Request
  • Hypervel\Http\Contracts\RequestContract

Sources: src/support/src/Facades/Request.php144-150 src/foundation/src/Application.php597-607

Complete Request API Reference

The following table summarizes all Request class methods organized by category:

Input Retrieval

MethodPurpose
input($key, $default)Get input value
query($key, $default)Get query parameter
post($key, $default)Get POST value
all($keys = null)Get all input including files
only($keys)Get subset of input
except($keys)Get all except specified keys
boolean($key, $default)Get as boolean
integer($key, $default)Get as integer
float($key, $default)Get as float
string($key, $default)Get as Stringable
date($key, $format, $tz)Get as Carbon
enum($key, $enumClass)Get as enum
collect($key)Get as Collection

Input Manipulation

MethodPurpose
merge($input)Merge new input
replace($input)Replace input values
mergeIfMissing($input)Merge only missing keys

Input Validation

MethodPurpose
has($keys)Check if keys exist
exists($keys)Alias of has()
missing($keys)Check if keys missing
filled($keys)Check if non-empty
isNotFilled($keys)Check if empty
anyFilled($keys)At least one filled
hasAny($keys)At least one exists
isEmptyString($key)Check if string is empty
whenHas($key, $callback)Conditional on existence
whenFilled($key, $callback)Conditional on filled

File Uploads

MethodPurpose
allFiles()Get all uploaded files
file($key, $default)Get specific file
hasFile($key)Check if file exists

URL Information

MethodPurpose
url()Get base URL
fullUrl()Get URL with query string
fullUrlWithQuery($query)Add query parameters
fullUrlWithoutQuery($keys)Remove query parameters
root()Get scheme and host
path()Get URL path
segments()Get path segments
segment($index, $default)Get specific segment
uri()Get Uri instance

Route Information

MethodPurpose
route($param, $default)Get route or parameter
routeIs(...$patterns)Check route name
fullUrlIs(...$patterns)Check full URL pattern
getDispatchedRoute()Get DispatchedRoute object

HTTP Information

MethodPurpose
method()Get HTTP method
getHost()Get hostname
getHttpHost()Get host with port
getPort()Get port number
getScheme()Get http/https
isSecure()Check if HTTPS
getSchemeAndHttpHost()Get scheme://host:port
ip() / getClientIp()Get client IP
bearerToken()Get Bearer token
headers()Get all headers
header($key, $default)Get specific header

Content Negotiation

MethodPurpose
isJson()Check if JSON content
wantsJson()Check if JSON requested
expectsJson()Probably expects JSON
accepts($types)Check if accepts types
prefers($types)Get preferred type
acceptsJson()Check if accepts JSON
acceptsHtml()Check if accepts HTML
acceptsAnyContentType()Accepts anything
getAcceptableContentTypes()Get Accept header types
getMimeType($format)Get MIME for format
getMimeTypes($format)Get all MIMEs for format

Request Type Detection

MethodPurpose
ajax() / isXmlHttpRequest()Check if AJAX
pjax()Check if PJAX
prefetch()Check if prefetch
isRange()Check if range request

Integration

MethodPurpose
hasSession()Check if session available
session()Get session instance
validate($rules, $messages, $attributes)Validate input
user($guard)Get authenticated user
getUserResolver()Get user resolver callback
setUserResolver($callback)Set user resolver
hasValidSignature($absolute)Verify URL signature
hasValidRelativeSignature()Verify relative signature
hasValidSignatureWhileIgnoring($ignore, $absolute)Verify with ignored params
hasValidRelativeSignatureWhileIgnoring($ignore)Relative with ignored params

PSR-7 Compatibility

MethodPurpose
getPsr7Request()Get underlying PSR-7 request

Sources: src/http/src/Request.php src/http/src/Contracts/RequestContract.php src/support/src/Facades/Request.php

Refresh this wiki

On this page