From 0be049fde98e9cdea974eb24be6a68cc40d70502 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Thu, 9 Oct 2014 16:20:04 +0000 Subject: [PATCH 1/2] Added the ability to call the api for a list of endpoints --- html/api_v0.php | 1 + html/includes/api_functions.inc.php | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/html/api_v0.php b/html/api_v0.php index 44bcc59fe5..1748863236 100644 --- a/html/api_v0.php +++ b/html/api_v0.php @@ -40,6 +40,7 @@ $app->group('/api', function() use ($app) { $app->post('/devices', 'authToken', 'add_device');//api/v0/devices (json data needs to be passed) $app->delete('/devices/:hostname', 'authToken', 'del_device');//api/v0/devices (json data needs to be passed) }); + $app->get('/v0', 'authToken', 'show_endpoints');//api/v0 }); $app->run(); diff --git a/html/includes/api_functions.inc.php b/html/includes/api_functions.inc.php index f9829b2a1e..e3de88d370 100644 --- a/html/includes/api_functions.inc.php +++ b/html/includes/api_functions.inc.php @@ -478,3 +478,15 @@ function get_vlans() { $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output); } + +function show_endpoints() { + global $config; + $app = \Slim\Slim::getInstance(); + $routes = $app->router()->getNamedRoutes(); + foreach($routes as $route) { + $output[$route->getName()] = $config['base_url'].$route->getPattern(); + } + $app->response->setStatus('200'); + $app->response->headers->set('Content-Type', 'application/json'); + echo _json_encode($output); +} From 24ee2541ee3ebdfc88d789fbb89dd222bb71c85c Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Thu, 9 Oct 2014 16:47:11 +0000 Subject: [PATCH 2/2] Defining output array as per scrutinizer --- html/includes/api_functions.inc.php | 1 + 1 file changed, 1 insertion(+) diff --git a/html/includes/api_functions.inc.php b/html/includes/api_functions.inc.php index e3de88d370..a38fab55c6 100644 --- a/html/includes/api_functions.inc.php +++ b/html/includes/api_functions.inc.php @@ -483,6 +483,7 @@ function show_endpoints() { global $config; $app = \Slim\Slim::getInstance(); $routes = $app->router()->getNamedRoutes(); + $output = array(); foreach($routes as $route) { $output[$route->getName()] = $config['base_url'].$route->getPattern(); }