/php-routes-class

A Routes class made in PHP. It uses part of the Express from node.js route concepts, and the Friendly URL class as dependency

Primary LanguagePHP

php Routes class

A REST PHP Routes class.

It uses the express (node.js) route concepts, in a very simple way.

This class needs the Friendly URL class as dependency and .htaccess file.


How to use

Set up

// URL = /version/1487
$url = new URL("http://localhost"); // Friendly URL class instance
$api = new ROUTE($url, ['name' => "SHAW", 'version' => '1.0']);
$api->define("/route/{{id}}", function ($api, $request) {
        $api->join($request); // you will see on the response an "id" position with "1487" as its value
});

version()

Displays the API current Version

join($array, $status = true)

It merges an array with the response of the API. $status set the response status to true or false

define($route, $callback)

It sets a new Route within a callback. You can set dynamic routes like this:

// URL = /version/1487
$api->define("/route/{{id}}", function ($api,$request) {
        $api->join($request); // you will see on the response an "id" position with "1487" as its value
});

route()

It basically calls the API, to execute whatever that route should do.

response($echo = false)

It will send the response. if $echo == true, will print it on the screen, otherwise will return as a JSON object