Routing in PHP
Learn how to make a single script that serves all the URL endpoints in our application.
We'll cover the following...
We'll cover the following...
Why routing
As we already know, we should handle our application’s HTTP requests in a single script. At the same time, we want our application to provide different resources depending on the URL. For this, we need a router, a module that parses the request and determines which piece of code should handle it based on the predefined configuration.
Using a router
So, how do we write a router? As usual, we don’t. Although writing it could be an ...