public static function slimSetup(\Slim\Slim &$slim, One_Scheme $scheme) { //TODO: read specs from behaviour options or from a file $opt = $scheme->get('behaviorOptions.restable'); $route = $opt['route']; // retrieve $slim->get("/{$route}", function () use($scheme) { One_Controller_Rest::restGetAll($scheme); }); // retrieve one $slim->get("/{$route}/:idOrAlias", function ($idOrAlias) use($scheme) { One_Controller_Rest::restGet($scheme, $idOrAlias); }); // create new $slim->post("/{$route}", function () use($scheme) { One_Controller_Rest::restPost($scheme); }); // update existing $slim->put("/{$route}/:idOrAlias", function ($idOrAlias) use($scheme) { One_Controller_Rest::restPut($scheme, $idOrAlias); }); // delete existing $slim->delete("/{$route}/:idOrAlias", function ($idOrAlias) use($scheme) { One_Controller_Rest::restDelete($scheme, $idOrAlias); }); }
protected function defineRoutes(\Slim\Slim $app) { $app->get('/event/:eventSlug/:talkSlug', array($this, 'index'))->name('talk'); $app->post('/event/:eventSlug/:talkSlug/star', array($this, 'star'))->name('talk-star'); $app->get('/talk/:talkStub', array($this, 'quick'))->name('talk-quicklink'); $app->post('/event/:eventSlug/:talkSlug/add-comment', array($this, 'addComment'))->name('talk-add-comment'); }
protected function defineRoutes(\Slim\Slim $app) { $app->get('/', array($this, 'index')); $app->get('/apps', array($this, 'apps'))->name('apps'); $app->get('/about', array($this, 'about'))->name('about'); $app->map('/contact', array($this, 'contact'))->via('GET', 'POST')->name('contact'); $app->get('/not-allowed', array($this, 'notAllowed'))->name('not-allowed'); }
public function generateRoutes() { foreach ($this->schema->table as $table) { $tableName = $this->_urlFriendly($table['name']); $this->slimApp->post($this->apiBasePath . "add-" . $tableName, $this->_addRecord($table)); $this->slimApp->get($this->apiBasePath . "fetch-" . $tableName . "s", $this->_fetchRecords($table)); $this->slimApp->get($this->apiBasePath . "get-" . $tableName . "/:id", $this->_getRecord($table)); $this->slimApp->get($this->apiBasePath . "get-" . $tableName . "-by/:key/:value", $this->_getRecordBy($table)); } }
protected function defineRoutes(\Slim\Slim $app) { $app->get('/event/:eventSlug/:talkSlug', array($this, 'index'))->name('talk'); $app->post('/event/:eventSlug/:talkSlug/star', array($this, 'star'))->name('talk-star'); $app->get('/talk/:talkStub', array($this, 'quick'))->name('talk-quicklink'); $app->get('/event/:eventSlug/:talkSlug/comments/:commentHash/report', array($this, 'reportComment'))->name('talk-report-comment'); $app->post('/event/:eventSlug/:talkSlug/add-comment', array($this, 'addComment'))->name('talk-add-comment'); $app->get('/:talkId', array($this, 'quickById'))->name('talk-quick-by-id')->conditions(array('talkId' => '\\d+')); $app->get('/talk/view/:talkId', array($this, 'quickById'))->name('talk-by-id-web1')->conditions(array('talkId' => '\\d+')); }
/** * 渡されたslimインスタンスにルートを登録 * @param \Slim\Slim $app */ public static function registration(\Slim\Slim $app) { // SlimのCSRF対策プラグインを有効化 $app->add(new \Slim\Extras\Middleware\CsrfGuard()); // トップページ $app->get('/', '\\Tinitter\\Controller\\TimeLine:show'); // 投稿一覧 $app->get('/page/:page_num', '\\Tinitter\\Controller\\TimeLine:show'); // 新規投稿系、保存 $app->post('/post/commit', '\\Tinitter\\Controller\\Post:commit'); }
public static function registration(\Slim\Slim $app) { // Slim縺ョCSRF蟇セ遲悶��繝ゥ繧ー繧、繝ウ繧呈怏蜉ケ蛹� $app->add(new \Slim\Extras\Middleware\CsrfGuard()); // 繝医ャ繝励��繝シ繧ク $app->get('/', '\\Tinitter\\Controller\\TimeLine:show'); // 謚慕ィソ荳�隕ァ $app->get('/page/:page_num', '\\Tinitter\\Controller\\TimeLine:show'); // 譁ー隕乗兜遞ソ邉サ縲∽ソ晏ュ� $app->post('/post/commit', '\\Tinitter\\Controller\\Post:commit'); }
private function addRoutesFromMeta(Slim $application, ClassMetadata $meta, Controller $controller) { $entitiesRoute = $this->getEntitiesRoute($meta); // Fetch entities route $application->get($entitiesRoute, function () use($meta, $controller) { $controller->getEntities($meta); }); // Create entity $application->post($entitiesRoute, function () use($meta, $controller) { $controller->createEntity($meta); }); $entityRoute = $this->getEntityRoute($meta, $entitiesRoute); // Get entity $application->get($entityRoute, function () use($meta, $controller) { $controller->getEntity($meta, func_get_args()); }); // Update entity $application->put($entityRoute, function () use($meta, $controller) { $controller->updateEntity($meta, func_get_args()); }); // Patch entity $application->patch($entityRoute, function () use($meta, $controller) { $controller->patchEntity($meta, func_get_args()); }); // Delete entity $application->delete($entityRoute, function () use($meta, $controller) { $controller->deleteEntity($meta, func_get_args()); }); // Handling associated entities foreach ($meta->getAssociationMappings() as $aName => $aData) { $aTargetClass = $meta->getAssociationTargetClass($aName); $aMeta = $this->getEntityMeta($aTargetClass); $aEntitiesRoute = $entityRoute . '/' . $aName; // Create associated entity // allow to create entity and link source together // POST /articles/1/tags will fetch article 1, create tag entity and // associate it to article 1 $application->post($aEntitiesRoute, function () use($meta, $aMeta, $controller, $aData) { $controller->createEntity($aMeta, $aData['fieldName'], $meta, func_get_args()); }); // List associated entities $application->get($aEntitiesRoute, function () use($meta, $controller, $aData) { $controller->getAssociatedEntities($aData['fieldName'], $meta, func_get_args()); }); // Associate two entities // POST /articles/1/tags/2 will associate article 1 to tag 2 $aEntityRoute = $this->getEntityRoute($aMeta, $aEntitiesRoute); $application->post($aEntityRoute, function () use($meta, $aMeta, $controller, $aData) { $controller->associateEntities($aMeta, $aData['fieldName'], $meta, func_get_args()); }); } return $application; }
public function __construct(Neo4j\Client $client, Slim\Slim $app, Theme $theme = null, array $options = null) { $this->setOptions($options); $this->app = $app; $this->client = $client; $this->schema = new Schema($client); if ($theme) { $this->setTheme($theme); } if ($this->hasOption('upload.directory')) { $this->setUploadDirectory($this->getOption('upload.directory')); } // Set up the home route. $app->get('/', Closure::bind(function () { $controller = new Controllers\HomeController($this->app, $this->schema, $this->client); $controller->read(); }, $this)); // Set up the uploads route. $app->get($this->getOption('path.format.uploads'), Closure::bind(function ($file_name) { $controller = new Controllers\UploadController($this->app); $controller->read($file_name); }, $this)); // Set up the search controller. $app->get($this->getOption('path.format.search'), Closure::bind(function () { $controller = new Controllers\SearchController($this->app, $this->schema, $this->client); $controller->run(); }, $this))->name('search'); // Set up the resources controller. $this->app->get($this->getOption('path.format.resources'), Closure::bind(function (array $resource_path) { $theme = $this->getTheme(); // Pass if not an instance or child of the default theme, as Theme#renderResource won't be present. // In non-standard use cases, this allows the user to use a regular Slim\View as the view. if (!$theme) { $this->getApp()->pass(); } $controller = new Controllers\FileController($this->app); if ($theme->hasResource($resource_path)) { $controller->read($theme->getResourcePath($resource_path)); } else { $this->getApp()->notFound(new Exceptions\Exception('Unknown resource "' . implode('/', $resource_path) . '".')); } }, $this))->name('resources'); // Set up a default handler for 404 errors. // Only Penelope application-generated exceptions are permitted. $app->notFound(function (Exceptions\Exception $e = null) { if (!$e) { $e = new Exceptions\NotFoundException('The requested page cannot be found.'); } $controller = new Controllers\Controller($this->app); $this->app->render('error', array('title' => $controller->_m('error_404_title'), 'error' => $e), 404); }); }
public function enable(Slim $app) { $this->app = $app; $this->config = $this->app->config('api'); $this->factory = new Factory($this->config['resources']); // Middleware $this->app->add(new Database()); $this->app->add(new ApiMiddleware($this->config)); // Routes $this->app->get($this->config['prefix'] . '/:resource/:id', [$this, 'getAction'])->conditions(['id' => '\\d+'])->name('resource_get'); $this->app->get($this->config['prefix'] . '/:resource', [$this, 'listAction'])->name('resource_get_list'); $this->app->put($this->config['prefix'] . '/:resource/:id', [$this, 'putAction'])->conditions(['id' => '\\d+'])->name('resource_put'); $this->app->post($this->config['prefix'] . '/:resource', [$this, 'postAction'])->name('resource_post'); $this->app->delete($this->config['prefix'] . '/:resource/:id', [$this, 'deleteAction'])->conditions(['id' => '\\d+'])->name('resource_delete'); }
/** * @param Slim $app * @param Resolver $resolver */ public function register(Slim $app, Resolver $resolver) { $app->get('/', function () use($app) { $app->redirectTo('transfer_form'); }); $app->get('/transfer-form', $resolver->resolve($app, 'ewallet.transfer_form_controller:showForm', function () { return [Identifier::fromString('ABC')]; }))->name('transfer_form'); $app->post('/transfer-funds', $resolver->resolve($app, 'ewallet.transfer_funds_controller:transfer', function () use($app) { /** @var \EwalletModule\Bridges\Zf2\InputFilter\TransferFundsInputFilterRequest $request */ $request = $app->container->get('ewallet.transfer_filter_request'); $request->populate($app->request->post()); return [$request]; }))->name('transfer_funds'); }
protected function setAssetsRoute() { $renderer = $this->debugbar->getJavascriptRenderer(); $this->app->get('/_debugbar/fonts/:file', function ($file) use($renderer) { // e.g. $file = fontawesome-webfont.woff?v=4.0.3 $files = explode('?', $file); $file = reset($files); $path = $renderer->getBasePath() . '/vendor/font-awesome/fonts/' . $file; if (file_exists($path)) { $this->app->response->header('Content-Type', (new \finfo(FILEINFO_MIME))->file($path)); echo file_get_contents($path); } else { // font-awesome.css referencing fontawesome-webfont.woff2 but not include in the php-debugbar. // It is not slim-debugbar bug. $this->app->notFound(); } })->name('debugbar.fonts'); $this->app->get('/_debugbar/resources/:file', function ($file) use($renderer) { $files = explode('.', $file); $ext = end($files); if ($ext === 'css') { $this->app->response->header('Content-Type', 'text/css'); $renderer->dumpCssAssets(); } elseif ($ext === 'js') { $this->app->response->header('Content-Type', 'text/javascript'); $renderer->dumpJsAssets(); } })->name('debugbar.resources'); $this->app->get('/_debugbar/openhandler', function () { $openHandler = new OpenHandler($this->debugbar); $data = $openHandler->handle($request = null, $echo = false, $sendHeader = false); $this->app->response->header('Content-Type', 'application/json'); $this->app->response->setBody($data); })->name('debugbar.openhandler'); }
function routes(\Slim\Slim $app) { $base = $this->getBasePath(); $app->get($base . '/', function () use($app) { $app->redirect($app->Doc->getBasePath() . '/api-doc/'); }); $app->get($base . '/api-doc/json', function () use($app) { $app->Doc->json(); }); $app->get($base . '/api-doc/', function () use($app) { $app->Doc->ui(); }); $app->get($base . '/api-doc/json/:name', function ($name) use($app) { $app->Doc->api($name); }); }
public function setUp() { parent::setUp(); $app = new Slim(); $app->get('/test', function () { })->name('test'); $this->ext = new Xhgui_Twig_Extension($app); }
public static function registrationRoute(\Slim\Slim $app) { $app->get('/', function () use($app) { $app->render('index.php'); }); $app->post('/form/', function () use($app) { $app->render('index.php', ['nickname' => $_POST['nickname']]); }); }
public function run() { if (isset($_GET['refresh'])) { $this->import(); } $this->slim->get('/', function () { $controller = new \Controller\IndexController(); $controller->indexAction(); })->name('index'); $this->slim->get('/portfolio/:album', function ($album) { $controller = new \Controller\PortfolioController(); $controller->albumAction($album); })->name('album'); $this->slim->get('/portfolio/:album/:image', function ($album, $image) { $controller = new \Controller\PortfolioController(); $controller->imageAction($album, $image); })->name('image'); $this->slim->run(); }
/** * Adds a backend routes * @param $appInstance * @return void */ public static function addRouteDefinitions(Slim $appInstance) { $appInstance->group('/admin', function () use($appInstance) { $appInstance->get('/', function () { print '<h1>A Simple Backend</h1>'; }); $appInstance->map("/chpass", function () use($appInstance) { if (EMA_ADMIN_CHPASS) { AdminPasswordChange_controller::process(); } else { $appInstance->pass(); } })->via('GET', 'POST'); $appInstance->map("/update", function () use($appInstance) { ClassAndMethodsDispatcher::updateGPMethods(); })->via('GET', 'POST'); $appInstance->post("/login", function () use($appInstance) { $appInstance->response->headers->set('Cache-Control', 'no-store'); if (isset($_POST['username']) && is_string($_POST['username']) && (isset($_POST['password']) && is_string($_POST['password']))) { try { try { $user = new UserAuth(); } catch (SessionExpired $e) { $user = new UserAuth(); } $user->userLogin($_POST['username'], $_POST['password']); if (!$user->isAdmin()) { $user->logout(); throw new LoginIncorrect('You are not allowed to login here'); } $appInstance->response->headers->set('Content-Type', 'application/json'); print json_encode($user->getSessionAuthData()); } catch (LoginIncorrect $e) { $appInstance->response->headers->set('Content-Type', 'text/plain'); $appInstance->response->setStatus(400); print $e->getMessage(); } } else { $appInstance->response->headers->set('Content-Type', 'text/plain'); $appInstance->response->setStatus(400); print 'Bad request'; } }); $appInstance->map('/logout', function () use($appInstance) { try { $user = new UserAuth(); if ($user->isUserLoggedInSimple()) { $user->logout(); } } catch (SessionExpired $e) { } })->via('GET', 'POST'); }); }
function RegisterHelp(SlimWebServiceRegistry $registry, \Slim\Slim $app) { $app->get('/', function () use($registry, $app) { // Print API documentation ApiHelpPage::Render($registry, $app); })->name("Default"); $app->get('/Help', function () use($registry, $app) { // Print API documentation ApiHelpPage::Render($registry, $app); })->name("Help"); }
function get($pattern, $controller, $method, $filter = null) { if (!is_callable($filter)) { $filter = function () { }; } return parent::get($pattern, $filter, function () use($controller, $method) { $instance = new $controller(); $args = func_get_args(); call_user_func_array(array($instance, $method), $args); }); }
private function _initRoutes() { $this->_slim->contentType('application/json'); $this->_slim->get('/basket/', array($this, 'getBaskets')); $this->_slim->get('/product/', array($this, 'getProducts')); $this->_slim->get('/basket/:id', array($this, 'getBasket')); $this->_slim->get('/basket/:id/item/', array($this, 'getBasketItems')); $this->_slim->get('/basket/:id/item/:prodId', array($this, 'getBasketItem')); $this->_slim->post('/basket/:id/item/', array($this, 'postBasketItem')); $this->_slim->put('/basket/:id/item/:prodId', array($this, 'putBasketItem')); $this->_slim->delete('/basket/:id/item/:prodId', array($this, 'deleteBasketItem')); }
public static function register_callbacks(Slim $app) { /* @var $router = /ActiveCRUD/Router */ $router = self::get_router(); $app->get('/CRUD/list', function () use($app, $router) { /* @var $router = /ActiveCRUD/Router */ self::get_router()->ar_list($app, self::$_models); }); $app->get('/CRUD/view/:table_name', function ($table_name) use($app, $router) { /* @var $router = /ActiveCRUD/Router */ self::get_router()->ar_view($app, self::$_models, $table_name); }); }
/** * Routes implemented by this class * * @param \Slim $app Slim application instance * * @return void */ protected function defineRoutes(\Slim\Slim $app) { $app->get('/user/logout', array($this, 'logout'))->name('user-logout'); $app->map('/user/login', array($this, 'login'))->via('GET', 'POST')->name('user-login'); $app->map('/user/register', array($this, 'register'))->via('GET', 'POST')->name('user-register'); $app->get('/user/verification', array($this, 'verification'))->name('user-verification'); $app->map('/user/resend-verification', array($this, 'resendVerification'))->via('GET', 'POST')->name('user-resend-verification'); $app->map('/user/username-reminder', array($this, 'remindUsername'))->via('GET', 'POST')->name('user-username-reminder'); $app->map('/user/password-reset', array($this, 'resetPassword'))->via('GET', 'POST')->name('user-password-reset'); $app->map('/user/new-password', array($this, 'newPassword'))->via('GET', 'POST')->name('user-new-password'); $app->get('/user/twitter-login', array($this, 'loginWithTwitter'))->name('twitter-login'); $app->get('/user/twitter-access', array($this, 'accessTokenFromTwitter'))->name('twitter-callback'); $app->get('/user/:username', array($this, 'profile'))->name('user-profile'); $app->get('/user/:username/talks', array($this, 'profileTalks'))->name('user-profile-talks'); $app->get('/user/:username/events', array($this, 'profileEvents'))->name('user-profile-events'); $app->get('/user/:username/hosted', array($this, 'profileHosted'))->name('user-profile-hosted'); $app->get('/user/:username/comments', array($this, 'profileComments'))->name('user-profile-comments'); $app->map('/user/:username/edit', array($this, 'profileEdit'))->via('GET', 'POST')->name('user-profile-edit'); }
/** * This function starts the Slim framework by calling it's run() method. */ public function run() { $responseOutputWriter =& $this->_hook->getResponseOutputWriter(); // define index endpoint $indexEndpoint = new SlimBootstrap\Endpoint\Index($this->_collectionEndpoints); $this->_app->get('/', function () use(&$responseOutputWriter, $indexEndpoint) { $responseOutputWriter->write($indexEndpoint->get()); })->name('index'); // define info endpoint $infoEndpoint = new SlimBootstrap\Endpoint\Info(); $this->_app->get('/info', function () use(&$responseOutputWriter, $infoEndpoint) { $responseOutputWriter->write($infoEndpoint->get()); })->name('info'); $this->_app->run(); }
/** @test */ function it_should_persist_an_event_published_inside_an_slim_route() { /** @var \Hexagonal\Bridges\Doctrine2\DomainEvents\EventStoreRepository $store */ $store = $this->entityManager->getRepository(StoredEvent::class); $publisher = new EventPublisher(); $middleware = new StoreEventsMiddleware(new PersistEventsSubscriber($store, new StoredEventFactory(new JsonSerializer())), $publisher); $app = new Slim(); $app->get('/', function () use($publisher) { $events = new SplObjectStorage(); $events->attach(A::transferWasMadeEvent()->build()); $publisher->publish($events); }); $app->add($middleware); Environment::mock(['REQUEST_METHOD' => 'GET']); $app->run(); $this->assertCount(1, $store->allEvents()); }
function routes(\Slim\Slim $app) { $base = $this->getBasePath(); $app->post($base . '/posts/search', function () use($app) { $app->Posts->search(); }); $app->post($base . '/posts/:id', function ($id) use($app) { $app->Posts->getById($id); }); $app->get($base . '/posts/:id', function ($id) use($app) { $app->Posts->getById($id); }); $app->post($base . '/posts', function () use($app) { $app->Posts->save(); }); $app->delete($base . '/posts/:id', function ($id) use($app) { $app->Posts->delete($id); }); }
private function loadMethodAnnotations(Slim $app, \ReflectionMethod $method, $newInstanceClass, $uri) { $methodAnnotations = $this->getMethodAnnotations($method); $uriMethod = ''; if (isset($methodAnnotations['SlimAnnotation\\Mapping\\Annotation\\Path'])) { $uriMethod = $methodAnnotations['SlimAnnotation\\Mapping\\Annotation\\Path']->uri; } $uri = $this->normalizeURI($uri, $uriMethod); if (isset($methodAnnotations['SlimAnnotation\\Mapping\\Annotation\\POST'])) { $app->post($uri, $method->invoke($newInstanceClass)); } if (isset($methodAnnotations['SlimAnnotation\\Mapping\\Annotation\\GET'])) { $app->get($uri, $method->invoke($newInstanceClass)); } if (isset($methodAnnotations['SlimAnnotation\\Mapping\\Annotation\\DELETE'])) { $app->delete($uri, $method->invoke($newInstanceClass)); } if (isset($methodAnnotations['SlimAnnotation\\Mapping\\Annotation\\PUT'])) { $app->put($uri, $method->invoke($newInstanceClass)); } }
/** * This methods will be called at application startup * @param $appInstance * @return void */ public static function addRouteDefinitions(Slim $appInstance) { $appInstance->get('/', function () { print '<h1>A simple frontend</h1>'; }); $appInstance->post("/login", function () use($appInstance) { $appInstance->response->headers->set('Cache-Control', 'no-store'); if (isset($_POST['username']) && is_string($_POST['username']) && (isset($_POST['password']) && is_string($_POST['password']))) { try { try { $user = new MembersAuth(); } catch (SessionExpired $e) { $user = new MembersAuth(); } $user->userLogin($_POST['username'], $_POST['password']); $appInstance->response->headers->set('Content-Type', 'application/json'); print json_encode($user->getSessionAuthData()); } catch (LoginIncorrect $e) { $appInstance->response->headers->set('Content-Type', 'text/plain'); $appInstance->response->setStatus(400); print $e->getMessage(); } } else { $appInstance->response->headers->set('Content-Type', 'text/plain'); $appInstance->response->setStatus(400); print 'Bad request'; } }); $appInstance->map('/logout', function () use($appInstance) { try { $user = new MembersAuth(); if ($user->isUserLoggedInSimple()) { $user->logout(); } } catch (SessionExpired $e) { } })->via('GET', 'POST'); }
public static function registration(\Slim\Slim $app) { $app->add(new \Slim\Extras\Middleware\CsrfGuard()); //top $app->get('/', '\\Quiz\\Controller\\Top:show'); //question $app->get('/questions', '\\Quiz\\Controller\\Question:show'); $app->get('/questions/new', '\\Quiz\\Controller\\Question:createShow'); $app->post('/questions/new', '\\Quiz\\Controller\\Question:createQuestion'); $app->get('/questions/update', '\\Quiz\\Controller\\Question:updateShow'); $app->post('/questions/update', '\\Quiz\\Controller\\Question:updateQuestion'); //quiz $app->get('/quizzes', '\\Quiz\\Controller\\Quiz:show'); $app->get('/quizzes/new', '\\Quiz\\Controller\\Quiz:createShow'); $app->post('/quizzes/new', '\\Quiz\\Controller\\Quiz:createQuiz'); //answer $app->post('/answer/start', '\\Quiz\\Controller\\Answer:answerStart'); $app->post('/answer/end', '\\Quiz\\Controller\\Answer:answerEnd'); //comment $app->post('/comment/create', '\\Quiz\\Controller\\Comment:createComment'); }
define('NAME_MAX_LENGTH', '100'); /* ------------------------------------------------------------------------------------------------ * OpenTok Initialization * -----------------------------------------------------------------------------------------------*/ $opentok = new OpenTok($config->opentok('key'), $config->opentok('secret')); /* ------------------------------------------------------------------------------------------------ * Routing * -----------------------------------------------------------------------------------------------*/ // Presence configuration // // Response: (JSON encoded) // * `apiKey`: The presence session API Key // * `sessionId`: The presence session ID $app->get('/presence', function () use($app, $config) { $responseData = array('apiKey' => $config->opentok('key'), 'sessionId' => $config->opentok('presenceSession')); $app->response->headers->set('Content-Type', 'application/json'); $app->response->setBody(json_encode($responseData)); }); // User enters // // Request: (JSON encoded) // * `name`: A name for the user that will appear in the UI // // Response: (JSON encoded) // * `token`: A token that can be used to connect to the presence session, which also identifies // the user to all other users who connect to it. // // NOTE: This request allows anonymous access, but if user authentication is required then the // identity of the request should be verified (often times with session cookies) before a valid // response is given. // NOTE: Uniqueness of names is not enforced.
//$allPostVars = $app->request->post(); //$allPutVars = $app->request->put(); //var_dump($allGetVars); //var_dump($allPostVars); //var_dump($allPutVars); class ResourceNotFoundException extends Exception { } // handle GET requests for /articles/:id $app->get('/articles/:id', function ($id) use($app) { try { // query database for single article $article = R::findOne('articles', 'id=?', array($id)); if ($article) { // if found, return JSON response $app->response()->header('Content-Type', 'application/json'); echo json_encode(R::exportAll($article)); } else { // else throw exception throw new ResourceNotFoundException(); } } catch (ResourceNotFoundException $e) { // return 404 server error $app->response()->status(404); } catch (Exception $e) { $app->response()->status(400); $app->response()->header('X-Status-Reason', $e->getMessage()); } }); // run $app->run();