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

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

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

# 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
  • Mapping plugin
    • Validate request parameters, map request body to entity and entity to response body.
    • See mapping chapter for more info.
  • Middleware plugin
  • 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 Accept header and in url suffix (/api/v1/users.xml)
    • See negotiation chapter for more info.
  • Debug plugin
  • Console plugin
  • 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
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