jeyroik / extas-api
There is no license information available for the latest version (3.0.0) of this package.
api package
3.0.0
2022-11-24 14:44 UTC
Requires
- jeyroik/extas-foundation: 6.*
- jeyroik/extas-id: 0.*
- slim/psr7: ^1.1
- slim/slim: ^4.5
Requires (Dev)
- jeyroik/extas-snuffbox: 1.*
- phpstan/phpstan: 0.*
- phpunit/phpunit: ^9
- ramsey/uuid: 4.*
- vlucas/phpdotenv: ^5.5
README
Description
Api for extas.
Using
php -S 0.0.0.0:8080 -t vendor/jeyroik/extas-api/public
.- You can add your own routes with a plugin by stage
extas.api.app.init
(seesrc/interfaces/extensions/IStageApiAppInit
for details).
Plugin example:
use extas\components\plugins\Plugin; use extas\interfaces\stages\IStageApiAppInit; use Slim\App; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; class PluginOwnRoute extends Plugin implements IStageApiAppInit { /** * @param App $app */ public function __invoke(App &$app): void { $app->post(// post/get/delete/put/patch/any/ '/my/route', function (RequestInterface $request, ResponseInterface $response, array $args) { // dispatching } ); } }
Using routes
//extas.app.storage.json
{ "plugins": [ { "class": "\\extas\\components\\plugins\\PluginRoutes", "stage": "extas.api.app.init" } ] }
//extas.app.json
{ "routes": [ { "name": "/json/v1/my-items", "title": "Items list", "description": "My items list", "method": "get", "class": "\\some\\routes\\ClassName" } ] }
// ClassName.php - route dispatcher class
<?php namespace some\routes; use extas\components\routes\dispatchers\JsonDispatcher; class ClassName extends JsonDispatcher { use TRouteList; protected string $repoName = 'my_items'; public function help(): ResponseInterface { //... } }
// my\interfaces\IMyItem
<?php namespace my\interfaces; class IMyItem { //... }
From here you can touch:
- GET /json/v1/my-items : you should see a list of my_items items.