Routing by custom Routes

Defining custom URL paths

In certain cases, you might want to define a custom routing instead of using the Routing by method-name

This can be accomplished using this annotation:


The Annotation gets placed in the comment above the method of your Api class. Here is a full example:


namespace My\Extension\Api;

use Nng\Nnrestapi\Annotations as Api;
use Nng\Nnrestapi\Api\AbstractApi;

 * @Api\Endpoint()
class Example extends AbstractApi
    * @Api\Route("GET /test/route")
    * @Api\Access("public")
    * @return array
   public function customRoutingTest()
      return ['message'=>'Hello!'];

When using custom routing, the method name is irrelevant and does not have to follow the pattern {request_method}{Classname}Action.

The above method customRoutingTest() would be executed when sending a GET Request to

Want to find out more?

Please refer to the @Api\Route section of this documentation for more details and examples.