Overwrite API endpoint by addon

Hi, is it possible to overwrite collection API endpoint for one method (get)?
I mean I want to have my own behavior in this api endpoint:


I have created new addon called languages and put this in bootstrap:

    $this->on('cockpit.rest.init', function ($routes) {
        $routes['collections.get'] = 'languages\\Controller\\RestApi';

I also created my own RestApi controller and there I have get method:

namespace languages\Controller;

class RestApi extends \LimeExtra\Controller {

     * Deprecated! use /entries instead
    public function get($collection = null) {
        return 'test';
        return $this->entries($collection);

Now when I go to: http://localhost:8080/api/collections/get/test?token=xxx
I expect to get to return string ‘test’ from my get method from addon but it not works. Anyone know how can I overwtire default api methods?

You can create complete custom api end points making the overriding of the default api unnecessary.

This is an example for creating an custom endpoint that combines the result of two different collections (references and jobs) to one single call:

  1. create a php file under //config/api. (e.g. “news-jobs-refs.php”)
  2. create an API key for the custom route (https://cockpit-install-url.com/restadmin/index)
  3. Example code for the news-jobs-refs.php:
$data = [];
// get collections
foreach (['references', 'jobs'] as $collection_name) {
    $data[$collection_name] = cockpit('collections')->find($collection_name, [
        'filter' => function($doc) { // make only published entries being used
            return $doc['published'];
        'sort' => [
            '_o' => 1
return $data;

Now your consumer can do something like this:

$data = json_decode(file_get_contents('https://cockpit-install-url.com/api/news-jobs-refs?token=<API TOKEN YOU HAVE GENERATED HERE>'), true);

PS. the API token def. (for https://cockpit-install-url.com/restadmin/index) would need to look like this:

Thank you, so there is no chance to overwrite default API endpoint by addons without changes in cockpi core.

I still don’t get why you should want this if you are able to create custom routes. Why can’t you just leave the default api untouched?