Contributte Apitte
Register Apitte using ApiExtension to your Nette-based application.
# config.neon
extensions:
    api: Apitte\Core\DI\ApiExtension
api:
    debug: %debugMode%
    catchException: true # Sets if exception should be catched and transformed into response or rethrown to output (debug only)
 1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
After that, create entrypoint to your Nette-based application. For example www/index.php looks like that.
// www/index.php
use Apitte\Core\Application\IApplication;
use App\Bootstrap;
require __DIR__ . '/../vendor/autoload.php';
Bootstrap::boot()
    ->createContainer()
    ->getByType(IApplication::class)
    ->run();
 1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
If you wanna combine Nette application and Apitte application together, www/index.php looks like that.
// www/index.php
use Apitte\Core\Application\IApplication as ApiApplication;
use App\Bootstrap;
use Nette\Application\Application as UIApplication;
require __DIR__ . '/../vendor/autoload.php';
$isApi = substr($_SERVER['REQUEST_URI'], 0, 4) === '/api';
$container = Bootstrap::boot()->createContainer();
if ($isApi) {
    // Apitte application
    $container->getByType(ApiApplication::class)->run();
} else {
    // Nette application
    $container->getByType(UIApplication::class)->run();
}
 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Plugins
# Prepared plugins
- Schema plugin
- Core plugin (enabled by default) which manage building and validation of whole api schema.
 - See schema chapter for more info.
 
 - OpenApi plugin
- OpenApi (opens new window) integration with Swagger UI (opens new window) support.
 - See openapi chapter for more info.
 
 - Mapping plugin
- Validate request parameters, map request body to entity and entity to response body.
 - See mapping chapter for more info.
 
 - Middleware plugin
- PSR-7 request/response integration, a.k.a. middlewares. Based on contributte/middlewares (opens new window).
 - See middlewares chapter for more info.
 
 - Decorator plugin
- Decorate request and response objects (e.q. authentication/authorization).
 - See decorators chapter for more info.
 
 - Negotiation plugin
- Transforms data into format requested in 
Acceptheader and in url suffix (/api/v1/users.xml) - See negotiation chapter for more info.
 
 - Transforms data into format requested in 
 - Debug plugin
- Debug api easily and display Tracy debug bar (opens new window) along with dumped response data.
 - See debug chapter for more info.
 
 - Console plugin
- Console commands for your api.
 - Based on symfony/console (opens new window)
 - See console chpater for more info.
 
 - Presenter plugin
- Route into your api through a single nette route and presenter.
 - See presenter chapter for more info.
 
 
# Custom plugin
api:
    plugins:
        App\Api\Plugin\YourAmazingPlugin:
 1
2
3
2
3
namespace App\Api\Plugin;
use Apitte\Core\DI\Plugin\Plugin;
class YourAmazingPlugin extends Plugin
{
    public static function getName() : string
    {
        return 'pluginName';
    }
    // Add new services, override existing or whatever you want
    // Take a look at existing plugins for inspiration
}
 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16