Routes

Introduction

All Exception app routes are defined in apps/APP-NAME/routes.php file.
This file is automatically loaded by the framework which provides two differents middlewares of http routes: web and api.

URL routing

Into routes file you can set URL routes using regular expressions for vars and using custom fuction into route.

For example:

Route::add('/about/',function(){
//here controller or function
});
Route::add('/pages/(.*)/',function($var1){
//here controller or function
});
Route::add('/test/(.*)/([0-9]*)/([a-zA-Z]*)/([0-9a-zA-Z]*)/',function($generic,$number,$text,$other){
//here controller or function
});
Route::add('/page-([0-9]*).html/',function($var1){
//here controller or function
},'get');
Route::add('/editpost/([0-9]*)/',function($var1){
//here controller or function
},'post');


Remember to declare desired and used variable into the functions and remember to use final slash (/) for each route definition.

Methods

Every routes can be uses with a specific HTTP method that you to specify after the Route:add function.

For example:

Route::add('/editpost/([0-9]*)/',function($var1){
//here controller or function
},'post');


Remember that by default method is GET and that POST method provides a web basic security protection that validates if POST request come from the same domain. (If you need to bypass it use "api" layer).

API middleware

Routes uses "Web" middleware by default but you can use API middleware for stateless applications simply declaring "api" var into add::Route function.

For example:

Route::add('/editpost/([0-9]*)/',function($var1){
//here controller or function
},'put', 'api');

Get variables

GET variables (as ?name=Foo&surname=Bar) are always avaible into every route.

Wrong directions

At the end of any routes files you can set the application routing in case of 403 or 404 errors.

Do you need help?

Write me an e-mail: [email protected]