Download the PHP package stonedz/pff2-rest without Composer
On this page you can find all versions of the php package stonedz/pff2-rest. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package pff2-rest
pff2-rest
REST module for stonedz/pff2 (v4) to build JSON APIs with:
- automatic REST method dispatch (
GET/POST/PUT/DELETE) - optional auth hook per request
- API version prefix routing (e.g.
api1/...) - JSON exception output for API requests
Requirements
- PHP +
stonedz/pff2v4 - Module dependencies declared in this package:
exception_handlerpff2-permissions
- Optional module:
pff2-annotations(only needed for annotation-based REST detection)
Installation
Enable modules in app config
In your app config.user.php, ensure the modules list includes:
If you want annotation-based REST detection, also add:
Module configuration
Create (or override) config at:
app/config/modules/pff2-rest/module.conf.yaml
Example:
Config keys
annotationName: method annotation name checked bypff2-annotations(when installed/enabled).enableAuth: iftrue, auth class is invoked before handling request.authType: currently informational in this module code.authClass: class name under namespace\pff\models\implementingIRestAuth.apiVersions: URL prefixes treated as API version roots (api1,v2, etc).
How routing works
If request URL starts with a configured API version, pff2-rest rewrites route from:
/api1/users/42
to controller/action form:
Api1_Users/index/42
Then, if controller implements IRestController, action is replaced by HTTP method:
GET→getHandlerPOST→postHandlerPUT→putHandlerDELETE→deleteHandlerOPTIONS→ immediate200
If pff2-annotations is installed and enabled, methods marked with the configured annotation name are also treated as REST requests.
Creating a REST controller
Implement pff\modules\Iface\IRestController:
Auth integration
When enableAuth: true, module creates:
\pff\models\<authClass>
and calls:
So your auth model should implement pff\modules\Iface\IRestAuth.
Example:
Error output format
For REST requests, uncaught exceptions are rendered as JSON:
HTTP status code is taken from exception code.
Notes
- The default sample value is
ApiAuthCkecker(spelling from legacy config). Use any class name you want, as long as it exists under\pff\models\and matchesauthClass. - This module sets JSON output automatically for matched REST requests.
- For non-REST requests, normal pff2 flow is unchanged.