HTTP Router

Apex comes with a straight forward interopable HTTP router. If you are already familiar with PHP frameworks and routers, you may want to skip this section and instead check out the HTTP Request Handling - Quick Reference guide as it contains all necessary information.

Basic Routes

All routes are stored within the /boot/routes.yml file, which defines which HTTP controller / middleware class each request will be forwarded to for processing. Below shows a small routes.yml example file:

routes:
    admin: Webapp\AdminPanel
    ajax: Webapp\Ajax
    members: MembersArea
    default: PublicSite

With the abov, the beginning of the UIR being requested only needs to match the route to be considered a hit. For example, upon visiting the URL:

https://localhost/admin/users/create

Since the URI begins with admin, it matches the first route in the above example, meaning the request will be forwarded to the Webapp\AdminPanel HTTP controller for processing. When the URI for a request does not match any of the routes, it will be forwarded to the default route, which in the case of the above example is the PublicSite route which simply uses auto-routing as explained later in this section.

Full Match Routes

Routes that require full matches to be triggered can be defined vy simply placing a $ sign at the end of the route, for example within the /boot/routes.yml file:

'catalog$': CatalogViewer

The above route will only be triggered if the URI is exactly http://localhost/catalog. If someone visits for example, http://localhost/catalog/electronics the above route will not be triggered due to the $ sign at the end meaning a full match is required.