In this episode, we're diving into the very beginning of how our app handles incoming web requests. Everything your app does starts with a request coming in, and we need a way to represent that request in our code. We'll talk about how our app uses either controllers or closures to handle routes—though that's something we'll see in more detail later on.
To work with requests in a standardized way, we're pulling in a PHP package that follows the PSR-7 standard for HTTP messages. This package helps us create request objects from PHP's global variables (like $_SERVER
, $_GET
, $_POST
, etc.), which makes things super consistent and easier to manage.
We go through installing the package, setting up a custom Request Service Provider so we can easily get a request object from our container anywhere in the app, and making sure it's shared (kind of like a singleton—there's only ever one instance per request).
After we've got the request in our hands, we do a little bit of experimentation—like outputting it to see what it looks like and accessing query parameters from the URL. You'll see that this makes extracting data from the request (whether it's query params, POST data, or even file uploads) really straightforward. Later on, as we build out routing and controllers, this request handling will plug right in, making it effortless to access any data sent to our app.