Quick api question

Hi, just started with cockpit and I have a very trivial question:
I have 5 collections, is it possible to get the data from them with 1 api request ?

1 Like

You can create a custom api endpoint.

with some code like this (not tested):

$collection1 = cockpit('collections')->find('collection1');
$collection2 = cockpit('collections')->find('collection2');
return compact('collection1', 'collection2');

Thanks ill try this.

It worked, but it does not like if I put access token in headers, also is it possible to manually authenticate in the custom endpoint in case i want to encrypt the everything related to the request ? kind of encrypted request > decrypt > data > encrypt > send back

Theoretically… You could add a custom route with all custom code. If you add a snippet to /config/bootstrap.php

$app->bind('/api/my_custom_endpoint', function() {
    $params = $this->params();
    $collection = $this->module('collections')->find('collection1');
    return $collection;

Then you should be able to request it via

(not tested)