GEMVC Request Lifecycle
Understand how HTTP requests flow through GEMVC framework. Learn about server adapters, unified request objects, and how your application code works identically on all webservers.
What You'll Learn
Server-Agnostic Architecture
How GEMVC works across different webservers
Request Flow
Step-by-step request processing
Server Adapters
ApacheRequest and SwooleRequest adapters
Video Coming Soon...
Overview
GEMVC's HTTP layer is designed to be completely server-agnostic. The same application code works identically on Apache, OpenSwoole, and Nginx without any changes.
Key Principle
Your app/ code never changes when switching webservers! The framework handles all platform differences automatically.
This is achieved through:
- Server Adapters - Convert webserver-specific requests to unified format
- Unified Request Object - Single interface for all webservers
- Response Abstraction - Consistent response handling across platforms
Server-Agnostic Architecture
GEMVC uses an adapter pattern to abstract webserver differences:
Server Adapters
- • ApacheRequest
- • SwooleRequest
- • NginxRequest (coming soon)
Unified Request
- • Single interface
- • Already sanitized
- • Type-safe access
Response Abstraction
- • JsonResponse
- • show() for Apache
- • showSwoole() for OpenSwoole
Apache/Nginx Request Lifecycle
Here's how requests flow through Apache/Nginx:
- • Sanitizes all headers
- • Sanitizes GET, POST, PUT, PATCH
- • Extracts files, cookies, auth headers
- • Creates unified Request object
OpenSwoole Request Lifecycle
Here's how requests flow through OpenSwoole:
- • Sanitizes headers
- • Sanitizes request data
- • Extracts files, cookies, auth headers
- • Creates unified Request object
Server Adapters
Server adapters convert webserver-specific requests to a unified format. They handle all sanitization and normalization automatically.
ApacheRequest Adapter
Purpose:
Converts Apache/PHP-FPM requests to unified Request object.
Key Features:
- ✓ Sanitizes all HTTP headers (
$_SERVER['HTTP_*']) - ✓ Sanitizes GET, POST, PUT, PATCH data
- ✓ Handles file uploads (
$_FILES) - ✓ Extracts cookies and auth headers
- ✓ Creates unified Request object
SwooleRequest Adapter
Purpose:
Converts OpenSwoole requests to unified Request object.
Key Features:
- ✓ Sanitizes OpenSwoole request headers
- ✓ Handles raw request body parsing
- ✓ Normalizes file uploads
- ✓ Filters dangerous cookies
- ✓ Creates unified Request object
Unified Request Object
The Request class provides a unified interface for all webservers. All data is already sanitized by the adapter.
Key Features:
- ✓ Already Sanitized - All inputs sanitized by adapter
- ✓ Type-Safe Access - Methods like
intValueGet(),stringValueGet() - ✓ Schema Validation -
definePostSchema(),defineGetSchema() - ✓ JWT Authentication - Built-in JWT token handling
- ✓ Query Helpers - Filtering, sorting, pagination
Request Properties:
- •
$request->post- POST data (sanitized) - •
$request->get- GET data (sanitized) - •
$request->put- PUT data (sanitized) - •
$request->files- File uploads - •
$request->auth()- JWT authentication
Response Handling
GEMVC abstracts responses to work across all webservers. Your application code is identical, and the framework handles the output differences.
Apache/Nginx
Uses JsonResponse->show():
- • Sets headers
- • Outputs JSON
- • Calls
die()to terminate
OpenSwoole
Uses JsonResponse->showSwoole():
- • Sets headers
- • Outputs JSON
- • Returns (no die - persistent process)
Your application code is identical! The framework automatically calls the correct method (show() or showSwoole()) based on the webserver.
Automatic Security
All server adapters automatically sanitize all inputs before your application code receives them:
HTTP Headers
All HTTP headers are sanitized automatically by the adapter.
Request Data
GET, POST, PUT, PATCH data is sanitized automatically (XSS prevention).
Cookies
Dangerous cookies are filtered automatically.
File Names
Uploaded file names are sanitized automatically.
Result: Your application code receives already-sanitized data! No need to manually sanitize inputs.
Key Benefits
Server-Agnostic Code
Your app/ code works identically on Apache, OpenSwoole, and Nginx without any changes.
Automatic Sanitization
All inputs are sanitized automatically by adapters before reaching your code.
Unified Interface
Same Request interface for all webservers - no platform-specific code needed.
Consistent Responses
Framework handles response output differences automatically.
🎉 Request Lifecycle Complete!
Now you understand how requests flow through GEMVC! Let's start building your first API.