Routing or router in web development is a mechanism where HTTP requests are routed to the code that handles them. To put simply, in the Router you determine what should happen when a user visits a certain page.
Here is a simple routing example from Laravel. When someone opens the website’s /test/ subpage, it will display a Hello World text.
Route::get('/test', function () { return 'Hello World'; });
Another example. Here we tell the application to run our verifyFields()
method in theĀ ContactFormController
class, when someone submits the form on the /contact/ page via POST method.
Route::post('/contact', 'ContactFormController@verifyFields');
There are many ready-to-use routing libraries – for example for PHP – which make it easy to add new routes to your application, without creating them one-by-one manually.