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

This package is auto-updated.

Last update: 2024-10-24 18:57:18 UTC


README

tests codecov.io PHPStan Enabled Extas Installer v3 Latest Stable Version Total Downloads Dependents

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 (see src/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.