Skip to content

Latest commit

 

History

History
43 lines (31 loc) · 1.09 KB

presenter.md

File metadata and controls

43 lines (31 loc) · 1.09 KB

Presenter

Integrate Apitte into nette/routing with a presenter.

Usage of that package is not recommended as it requires unnecessary conversion of nette request into psr-7 request. It also adds headers from nette response configuration which are usually mean for UI, not an API.

Presenter is currently incompatible with middlewares.

Setup

Configure presenter mapping.

application:
    mapping:
        Apitte: Apitte\Presenter\*Presenter

Prepend ApiRoute to your router. Therefore you can reach your API at <project>/api.

namespace App\Router;

use Apitte\Presenter\ApiRoute;
use Nette\Application\IRouter;
use Nette\StaticClass;

class RouterFactory
{
    use StaticClass;

    public static function createRouter(): IRouter
    {
        $router = new RouteList;
        $router[] = new ApiRoute('api');
        $router[] = new Route('<presenter>/<action>', 'Homepage:default');
        return $router;
    }
}

In index.php drop Apitte\Core\Application\IApplication and keep Nette\Application\Application only.