Registering Endpoints

Preparing a class to be used as an TYPO3 RestAPI Endpoint

To make sure that the TYPO3 RestApi "knows" it can route a request to your class and method, you need to register the class.

There are two alternative ways this can be done:

  • On a per-class base using the @Api\Endpoint() Annotation – or
  • globally for a complete namespace using \nn\rest::Endpoint()->register() in the ext_localconf.php of your extension.

You should decide using one of both, depending on your individual architecture.

  1. Alternative 1: Registering an Endpoint using Annotations

    Simply add the @Api\Endpoint() Annotation to the comment block above your class. The nnrestapi will automatically parse the DocComment and register your endpoint.

    You can find out more on this page.

    <?php
    
    namespace My\Extension\Api;
    
    use Nng\Nnrestapi\Annotations as Api;
    use Nng\Nnrestapi\Api\AbstractApi;
    
    /**
     * @Api\Endpoint()
     */
    class Example extends AbstractApi
    {
      // Your methods
    }
    Copied!
  2. Alternative 2: Global registry of a namespace

    In your ext_localconf.php you can let nnrestapi automatically register all endpoints in a certain namespace.

    Example: If all of your Endpoints are in the namespace My\Extension\Api\* then you could have them all automatically registered by adding this code to your ext_localconf.php.

    // Register path to my endpoints		
    \nn\rest::Endpoint()->register([
        'namespace' => 'My\Extension\Api'
    ]);
    Copied!

    By registering a global namespace for all your endpoints you can now dismiss the @Api\Endpoint() Annotation in the DocComment of your class:

    <?php
    
    namespace My\Extension\Api;
    
    use Nng\Nnrestapi\Annotations as Api;
    use Nng\Nnrestapi\Api\AbstractApi;
    
    /**
     * Nothing needed here :)
     */
    class Example extends AbstractApi
    {
      // Your methods
    }
    Copied!