Skip to content

Commit

Permalink
Add meaningful API root endpoint (#1771)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimsafley authored Nov 3, 2021
1 parent 2273a59 commit 358ebeb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
14 changes: 14 additions & 0 deletions application/src/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Laminas\Mvc\Controller\AbstractRestfulController;
use Laminas\Mvc\MvcEvent;
use Laminas\Stdlib\RequestInterface as Request;
use Laminas\View\Model\ViewModel;

class ApiController extends AbstractRestfulController
{
Expand Down Expand Up @@ -57,6 +58,19 @@ public function getList()
{
$this->setBrowseDefaults('id', 'asc');
$resource = $this->params()->fromRoute('resource');

if (null === $resource) {
$view = new ViewModel;
$view->setTerminal(true);
$view->setTemplate('omeka/api/root');
$apiResources = $this->api->search('api_resources')->getContent();
usort($apiResources, function ($a, $b) {
return strcmp($a->id(), $b->id());
});
$view->setVariable('apiResources', $apiResources);
return $view;
}

$query = $this->params()->fromQuery();
$response = $this->api->search($resource, $query);

Expand Down
15 changes: 15 additions & 0 deletions application/view/omeka/api/root.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<h1>Omeka S REST API</h1>
<p><?php echo $this->translate('This is the REST API root endpoint for this Omeka S installation. Below is a list of available API resources and links to their endpoints. Some resources and features require authentication.'); ?></p>
<ul>
<?php foreach ($apiResources as $apiResource): ?>
<li><?php echo $this->hyperlink(
$apiResource->id(),
$this->url('api/default', ['resource' => $apiResource->id()], ['force_canonical' => true, 'query' => ['pretty_print' => true]], true)
); ?></li>
<?php endforeach; ?>
</ul>
<p><?php echo $this->hyperlink(
$this->translate('Omeka S REST API documentation'),
'https://omeka.org/s/docs/developer/api/rest_api/',
['target' => '_blank']
); ?></p>

0 comments on commit 358ebeb

Please sign in to comment.