Wallogit.com
2017 © Pedro Peláez
Tiny RESTful router
tiny-rest-router is a simple library for PHP 5.6+., (*1)
Features, (*2)
tiny-rest-router is PSR-0 compliant and can be installed using composer.
Simply add ashwoodslightfoot/tiny-rest-router to your composer.json file., (*3)
{
"require": {
"ashwoodslightfoot/tiny-rest-router": "*"
}
}
or use a console command:
composer require "ashwoodslightfoot/tiny-rest-router:*" in your site root folder., (*4)
Add a rest folder to your project root folder. Example: /var/www/mysite/rest.
Configure your http server to add route for rest/index.php., (*5)
Make a file .htaccess in your rest folder, (*6)
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?path=$1 [NC,L,QSA]
Add this part to your site configuration file., (*7)
location /rest {
rewrite ^/rest(.*)$ $1&$args break;
try_files $uri $uri/ /rest/index.php?path=$uri&args;
}
See a simple example YourSiteFolder/vendor/ashwoodslightfoot/tiny-rest-router/examples/rest/index.php, (*8)
See a class hierarchy YourSiteFolder/vendor/ashwoodslightfoot/tiny-rest-router/examples/resources/v1.
The folder contains classes for RESTful API v1., (*9)