Skip to content

Instantly share code, notes, and snippets.

@andyvanee
Last active January 13, 2022 00:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyvanee/6262c59a369ec9d4ed2e1ef221434cf8 to your computer and use it in GitHub Desktop.
Save andyvanee/6262c59a369ec9d4ed2e1ef221434cf8 to your computer and use it in GitHub Desktop.
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