adawolfa/restte

REST support for Nette Framework.

dev-master / 1.0.x-dev 2017-11-15 20:22 UTC

README

Restte is simple REST support for Nette Framework.

Routing

You can now restrict your routes to a specified HTTP method:

$route = new Restte\Application\Routes\Route('GET|POST resource', 'Resource:');

For CRUD(L) operations, use following route:

$route = new Restte\Application\Routes\CRUD('resource', 'Resource');

Your presenter is supposed (but not required) to have following methods:

  • default() (listing)
  • read($id)
  • create()
  • update($id)
  • delete($id)

For NEON support, do this:

routing:
	routeClass: Restte\Application\Routes\AutoRoute
	routes:
		'basic': 'Presenter:basic'
		'GET|POST get-post': 'Presenter:getPost'
		'CRUD resource': 'Resource'

Presenter

In order to use Restte\Application\Presenter, add the compiler extension in your NEON:

extensions:
    restte: Restte\DI\RestteExtension

You can use much more simpler presenter API now:

class Presenter extends Restte\Application\Presenter
{

    function default()
    {
        return 'Hello World.'; // JSON response: "Hello World."
    }

    function value($value) // Obtains parameter from GET.
    {
        return ['value' => $value]; // JSON response: {"value": 123}
    }

    function create(): void
    {
        $this->result(201); // Returns empty response with status 201.
    }

    function delete(): void
    {
        $this->error(400); // Returns empty response with status 400.
    }

}