Cirno-php is a light-weight php api framework for rapid development, based on Flight and Medoo, with apiDoc support.
Cirno-php helps create api with many AUTOMATICAL operations, which saves your massive time.
- Auto generate http methods, routes into files.
- Auto parameters basic filte.
- Auto user permissions filte
Let's take an example:
Create a file src/Api/Calculator.php
<?php
namespace App\Api;
class Calculator
{
/**
* @api {get} /calc/sqrt Calculate sqrt(num)
* @apiName sqrt
* @apiGroup Calculator
* @apiVersion 0.2
* @apiPermission none
* @apiParam {integer{0-200}} num The number to be calculated.
* @apiSuccess {integer} result The result of calculation.
* @apiSuccessExample
* {
* "result": 225
* }
*/
public function mySqrt()
{
$num = \App::$api->request()->query->num;
\App::$api->json([
"result" => $num * $num
]);
}
}
And execute:
$ php generator.php run
You can see some files generated:
//file: src/common/route.php
<?php
$apiWelcome = new \App\Api\Welcome();
Flight::route('GET /', array($apiWelcome, 'index'));
//file: src/common/rule.php
return [
'/calc/sqrt' => [
'param' => [
'num' => [
'type' => 'integereger',
'min' => 0,
'max' => 200,
'required' => true,
],
],
],
];
//file: src/common/permission.php
<?php
return[
'/calc/sqrt'=>'none',
];
And then we go to http://127.0.0.1:8080/calc/sqrt?num=10
We got:
{
"result": 100
}
What if http://127.0.0.1:8080/calc/sqrt?num=1000
?
{
"message": "Parameter `num` is expected to be less than 200. "
}
And what if http://127.0.0.1:8080/calc/sqrt?ss=1000
?
{
"message": "Mising required parameter."
}
And http://127.0.0.1:8080/calc/sqrt?num=
?
{
"message": "Parameter `num` is given but it has empty value."
}
As you can see, what you need to do is just write API code. API comments will be parsed.