Powerfull API [REST/Relay/Middleware/GraphQL/DataQL] for Nette Framework

v0.3 2017-08-11 14:33 UTC


💥 Powerful API (PSR-7, REST, Relay, Middleware, GraphQL, DataQL, Annotations) for Nette Framework.

Build Status Code coverage Licence

Downloads this Month Downloads total Latest stable

Discussion / Help

Join the chat


composer require contributte/api


State Version Branch PHP
development dev-master master >= 5.6
stable ^0.3.0 master >= 5.6


This really powerful annotation-based API library is build on top of the PSR-7 standard. It reuses immutable Request & Response objects. It's well known that Presenters are the alpha and the omega in Nette applications. The presenters are not very suitable for API requests.

We have taken an idea from Java (Spring Framework) and many others and together we have created a Controller-based API. With full annotation support.

Controllers are small objects which can be registered in DIC as services (same as Presenters). They have a few public annotated methods. If one of the methods is matched by a router, it is called with ApiRequest and ApiResponse passed objects.

That's all. Take a look, it's really simple.

namespace App\Controllers;

use Contributte\Api\Annotation\Controller\Controller;
use Contributte\Api\Annotation\Controller\Method;
use Contributte\Api\Annotation\Controller\Path;
use Contributte\Api\Annotation\Controller\RootPath;
use Contributte\Api\Http\ApiRequest;
use Contributte\Api\Http\ApiResponse;
use Contributte\Api\UI\Controller\IController;

 * @Controller
 * @RootPath("/hello")
final class HelloController implements IController

     * @Path("/world")
     * @Method("GET")
     * @param ApiRequest $request
     * @param ApiResponse $response
     * @return ApiResponse
    public function index(ApiRequest $request, ApiResponse $response)
        return $response->writeBody('Hello world!');

And register your controller as service.

    - App\Controllers\HelloController

As you can see, the architecture is ultra simple. ApiRequest & ApiResponse extend PSR-7, so you can re-use these declared methods.



Milan Felix Šulc

The development is sponsored by Tlapnet and a lot of coffeees. Thank you guys! 👍

Thank you for testing, reporting and contributing.