REST support for Nette Framework.

dev-master / 1.0.x-dev 2018-01-19 23:15 UTC


Restte is simple REST support for Nette Framework.


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:

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


Note: Presenter is called a Resource in terms of this project.

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

    restte: Restte\DI\RestteExtension

You can use much more simpler controller API now:

class Presenter extends Restte\Application\Resource

    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.