Just another Phalcon RESTful webservice. It use Phalcon annotation routing for advanced and flexible routing configuration.
All routing must be placed in app/controllers
and must have Controller
suffix for class name. If your controller name is Example
then class name is ExampleController
. You can limit max request to specific API key or method. Limiting max request for API key can be set in Class Annotation, It will limit API key to access all method inside class. Also if you want to limit specific method you can set in Method Annotation, it will limit all API key to accessing this method.
@RoutePrefix("your-prefix-url-here")
- required
@Api(level=1-10, limits={"key": {"increment": "-1 month", "limit": 1000}})
- optional
@Get("/")
- required
@Post("/")
- required
@Put("/)
- required
@Delete("/")
- required
@Auth("your-auth-driver")
- optional
@Limit({"increment": "-1 hour", "limit": 50})
- optional
use Phalcon\Mvc\Controller;
/**
* @RoutePrefix("/v1/example")
* @Api(level=1,
* limits={
* "key" : {
* "increment" : "-1 day", "limit" : 1000}
* }
* )
*/
class ExampleController extends Controller
{
/**
* @Get("/")
* @Limit({"increment": "-1 hour", "limit": 50});
* @Auth("basic")
* @Whitelist()
*/
public function getAction()
{
// Your Logic here
}
/**
* @Post("/")
* @Limit({"increment": "-1 hour", "limit": 50});
* @Auth("basic")
*/
public function addAction()
{
// Your Logic here
}
}
You add additional layer for security by add authentication, Auth can only enabled per class method by add annotation.
This is enable HTTP auth basic when user request webservice.
Response are handled by ellipsesynergie/api-response you can access this library via phalcon DI using apiResponse
/**
* @Get("/")
* @Limit({"increment": "1 hour", "limit": 50});
* @Auth("basic")
*/
public function getAction()
{
$this->apiResponse->withArray(
[
"name" => "Jowy"
],
[
"My-Custom-Response-Header" => "It rocks"
]
);
}
php vendor/bin/phinx migrate
php vendor/bin/codecept run
- Improve documentation
- Add IP based whitelist/blacklist (implemented)
- Add IP based limitting
- Add dashboard for monitoring webservice