entrydo/rest-route

Route for Nette framework that supports single action presenters and HTTP methods.

v2.2.1 2018-01-14 02:03 UTC

This package is auto-updated.

Last update: 2024-10-16 11:10:13 UTC


README

Routes for Nette single action presenters with HTTP methods support.

Install

Easiest way is by composer composer require odbav-to/presenter-route

You have to register IndependentSingleActionPresenter extension in your config.neon:

extensions:
   	- Symplify\SymfonyEventDispatcher\Adapter\Nette\DI\SymfonyEventDispatcherExtension
   	- Symplify\SymbioticController\DI\IndependentSingleActionPresenterExtension

And you are ready to go :-).

Routes

use Entrydo\RestRoute\Route;
use Nette\Application\Routers\RouteList;

$router = new RouteList();

$router[] = new Route('/', HomepagePresenter::class);

REST routes

Support for GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS HTTP methods.

$router[] = RestRoute::get('/', HomepagePresenter::class);
// or
$router[] = new Route('/', HomepagePresenter::class, [IRequest::GET]);
$router[] = new RestRoute::post('/', HomepagePresenter::class);
// or
$router[] = new Route('/', HomepagePresenter::class, [IRequest::POST]);
$router[] = new RestRoute::put('/', HomepagePresenter::class);
// or
$router[] = new Route('/', HomepagePresenter::class, [IRequest::PUT]);
$router[] = new RestRoute::delete('/', HomepagePresenter::class);
// or
$router[] = new Route('/', HomepagePresenter::class, [IRequest::DELETE]);
$router[] = new RestRoute::patch('/', HomepagePresenter::class);
// or
$router[] = new Route('/', HomepagePresenter::class, [IRequest::PATCH]);
$router[] = new RestRoute::head('/', HomepagePresenter::class);
// or
$router[] = new Route('/', HomepagePresenter::class, [IRequest::HEAD]);
$router[] = new RestRoute::options('/', HomepagePresenter::class);
// or
$router[] = new Route('/', HomepagePresenter::class, [IRequest::OPTIONS]);

For multiple HTTP methods use Route and 3rd parameter:

$router[] = new Route('/', HomepagePresenter::class, [IRequest::GET, IRequest::POST, IRequest::DELETE]);