Hi,
I've searched quite a bit, but could not find any information as to how one could implement API versioning with the Phalcon Micro framework.
What I'm trying to have the micro framework handle is this: https://myapp/api/v1/say/welcome/dude
, as well as https://myapp/api/v2/say/hi/dude
But whereas this works:
<?php
$app = new \Phalcon\Mvc\Micro;
$app->get('/say/welcome/{name}', function ($name) {
echo "<h2>Hi there, $name!</h2>";
});
This does not:
<?php
$app = new \Phalcon\Mvc\Micro;
$app->get('/api/v1/say/welcome/{name}', function ($name) {
echo "<h2>Hi there, $name!</h2>";
});
$app->notFound(function () use ($app) {
$app->response->setStatusCode(404, "Not Found")->sendHeaders();
echo 'This is crazy, but this page was not found!';
});
$app->handle();
Apache does not find the resource.The notFound
handler is not even being invoked.
The directory structure is dead simple:
www
└── public
├── index.php
├── .htaccess
└── api
└── v1
└── index.php
└── .htaccess
Both .htaccess files
files contain the same instructions:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>
I've been trying to fiddle with the RewriteCond
and RewriteRule
setting in the .htaccess files
, but to no avail...
Am I taking the wrong approach for API versioning?
If not, how can I get this to work?
Many thanks for your ideas and input,
Steven
P.S.: Using PHP-fpm 5.5 as FastCGI on Apache 2.2.22 with Phalcon 1.2.6 on a Debian 7 VM