Cit*_*zen 5 php api rest standards coding-style
在一个宁静的水果API中,请求假定如下:
api/fruit
api/fruit?limit=100
api/fruit/1
api/fruit?color=red
Run Code Online (Sandbox Code Playgroud)
我认为必须有一个标准的功能来完成这项工作.例如,某些东西可能很容易转化为fruit.class.php.
fruit.class.php
function get ($id, $params, $limit) {
// query, etc.
}
Run Code Online (Sandbox Code Playgroud)
所以对于我上面的例子,代码看起来像
api/fruit
$fruit = $oFruit->get();
Run Code Online (Sandbox Code Playgroud)api/fruit?limit=100
$fruit = $oFruit->get(NULL, NULL, 100);
Run Code Online (Sandbox Code Playgroud)api/fruit/1
$fruit = $oFruit->get(1);
Run Code Online (Sandbox Code Playgroud)api/fruit?color=red
$fruit = $oFruit->get(NULL, array('color' => 'red'));
Run Code Online (Sandbox Code Playgroud)有这样的行业标准还是API /数据库功能总是一团糟?我真的很想标准化我的功能.
| 归档时间: |
|
| 查看次数: |
221 次 |
| 最近记录: |