$exampleCollection->setLazy(true)->setPrefix('/v1/example')->setHandler('\\PhalconRest\\Controllers\\ExampleController'); // Set Access-Control-Allow headers. $exampleCollection->options('/', 'optionsBase'); $exampleCollection->options('/{id}', 'optionsOne'); // First paramter is the route, which with the collection prefix here would be GET /example/ // Second paramter is the function name of the Controller. $exampleCollection->get('/', 'get'); // This is exactly the same execution as GET, but the Response has no body. $exampleCollection->head('/', 'get'); // $id will be passed as a parameter to the Controller's specified function $exampleCollection->get('/{id:[0-9]+}', 'getOne'); $exampleCollection->head('/{id:[0-9]+}', 'getOne'); $exampleCollection->post('/', 'post'); $exampleCollection->delete('/{id:[0-9]+}', 'delete'); $exampleCollection->put('/{id:[0-9]+}', 'put'); $exampleCollection->patch('/{id:[0-9]+}', 'patch'); $app->mount($exampleCollection); /** * After a route is run, usually when its Controller returns a final value, * the application runs the following function which actually sends the response to the client. * * The default behavior is to send the Controller's returned value to the client as JSON. * However, by parsing the request querystring's 'type' paramter, it is easy to install * different response type handlers. Below is an alternate csv handler. */ $app->after(function () use($app) { // OPTIONS have no body, send the headers, exit if ($app->request->getMethod() == 'OPTIONS') { $app->response->setStatusCode('200', 'OK'); $app->response->send(); return;