Skip to content

Instantly share code, notes, and snippets.

@andyvanee
Last active Jan 13, 2022
Embed
What would you like to do?
An example of a public endpoint in cockpit
<?php
// Place this file at config/api/public/testing.php
// Replace `mycollection` with the name of one of your collections
// Access it at http://yoursite.com/api/public/testing?myarg=testing
try {
$arg = $this->param('myarg')
$items = cockpit('collections')->find('mycollection', ['limit' => 10]);
return ['arg' => $arg, 'items' => $items];
} catch (\Throwable $th) {
return ['error' => $th->getMessage() . "\n" . $th->getTraceAsString()];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment