ashwoodslightfoot / tiny-rest-router
小型RESTful路由器
0.1.9
2021-09-07 12:04 UTC
Requires
- php: >=5.4.0
README
tiny-rest-router 是一个为PHP 5.6+设计的简单库。
特性
- 可读的HTTP方法支持(GET, PUT, POST, DELETE, HEAD, PATCH和OPTIONS)
- 自动解析
- 自动使用类和子类
安装
Composer
tiny-rest-router
符合PSR-0规范,可以使用 composer 安装。
只需将 ashwoodslightfoot/tiny-rest-router
添加到您的 composer.json 文件中。
{
"require": {
"ashwoodslightfoot/tiny-rest-router": "*"
}
}
或者使用控制台命令:在网站根目录下执行 composer require "ashwoodslightfoot/tiny-rest-router:*"
。
如何配置HTTP服务器
在项目根目录中添加一个 rest
文件夹。例如:/var/www/mysite/rest
。配置您的HTTP服务器以添加对 rest/index.php
的路由。
Apache
在 rest
文件夹中创建一个 .htaccess
文件
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?path=$1 [NC,L,QSA]
Nginx
将这部分添加到您的网站配置文件中。
location /rest {
rewrite ^/rest(.*)$ $1&$args break;
try_files $uri $uri/ /rest/index.php?path=$uri&args;
}
如何使用
查看简单示例 YourSiteFolder/vendor/ashwoodslightfoot/tiny-rest-router/examples/rest/index.php
查看类层次结构 YourSiteFolder/vendor/ashwoodslightfoot/tiny-rest-router/examples/resources/v1
。该文件夹包含RESTful API v1的类。