The HTTP layer in Apivalk provides a robust, type-safe, and structured way to handle the web request/response cycle. It bridges the gap between raw PHP superglobals and your business logic.
Requests in Apivalk are more than just wrappers around $_GET and $_POST. They are strongly typed objects that automatically populate and validate themselves based on your documentation.
Base Class: AbstractApivalkRequest
Data Storage: Data is organized into “Bags” (Query, Body, Path, Header, File).
Routing: The Router matches the incoming request URI and method to a specific Controller.
Request Preparation: The framework instantiates the controller and its associated AbstractApivalkRequest.
Population & Validation: The Request object is populated from superglobals. RequestValidationMiddleware then ensures the data matches the defined schema.
Execution: The Controller’s __invoke() method is called with the populated Request.
Return: The Controller returns an AbstractApivalkResponse.
Rendering: The Renderer (e.g., JsonRenderer) converts the Response object into the final HTTP output.
Predictability: Every endpoint follows the same pattern, making the codebase easier to navigate.
Type Safety: You never have to wonder if a variable is a string or an integer; the framework guarantees it before your code runs.
Zero Boilerplate: Automatic population and validation mean you focus only on business logic.
Documentation Synergy: Because the HTTP layer is driven by the same definitions used for OpenAPI generation, your implementation and documentation are always in sync.