I'm using Phalcon\Mvc\Router to map the routes and I have a GET route /api/test like this,
$router = new \Phalcon\Mvc\Router(false);
$router->addGet('/api/test', [
'module' => 'api',
'controller' => 'test',
'action' => 'testapi',
]);
I'm able to make a GET request to this route and I'm able to get a 200 response, but if I make the method an invalid HTTP method and make a request (as below) it's also givinh me 200 response.
curl --location --request NOTHTPPMETHOD 'http://localhost/api/test'
I have tried changing addGet to add and passing the method
I have tried chaining the via function in Phalcon\Mvc\Router and passig ['GET']
That's the expected behaviour. What your app is missing is to implement the
notFoundmethod. Add to your router:Or in a REST API:
Another useful method is
error:In this way your app can respond with custom messages and http status codes to failed requests.