[DEV HELP] APIHandler - how to use it in the generic plugin


I want to use the APIHandler class in my generic plugin but I can’t figure out the way how to use it.
I know how to use a normal Handler class - using LoadHandler hook - and everything would be fine making it that way but I really need to have control over HTTP status codes, proper JSON response, etc and for that I need APIHandler.

Is there someone who made it? Or someone who can help me or tell me if it is even possible?

What I did already:
I registered to the Hook named LoadHandler, like that:

 if ($this->getEnabled() && $page == 'pluginapisite') {
        define('HANDLER_CLASS', 'PluginApiHandler');
        return true;

In PluginApiHandler:

  function getEndpointPattern: 
  	return $this->_pathPattern = '/{contextPath}/' . $this->_handlerPath;


 $this->_handlerPath = 'pluginapisite';
 $this->_endpoints = array (
    'GET' => array (
             array (
                    'pattern' => $this->getEndpointPattern(), 
                    'handler' => array($this, 'getSmthng')

And the biggest problem for me right now is to not get 404, at: https://website.com/index.php/Journal/pluginapisite

What should I do with index function?

Is this even possible to make it this way?


The Controller Handlers are deprecated.

So I’m having the same problem trying to understand how to use an APIHandler to replace them in a plugin.

Didn’t find any examples of APIHandlers used into plugins, and have no clue how to register the APIHandler to serve the requests on a RESTful manner.