1
votes

I am trying to create a simple REST API using Phalcon PHP. I setup up Phalcon with wamp and followed this tutorial http://docs.phalconphp.com/pt/latest/reference/tutorial-rest.html for simple rest api But I am not able to access it at http://localhost/my-rest-api/api/robots (Error: The requested URL /my-rest-api/api/robots was not found on this server.) My-rest-api is in www directory of wamp, can anyone point out my mistake?

If I try to access http://localhost/my-rest-api/index.php I get these two errors

( ! ) Fatal error: Uncaught exception 'Phalcon\Mvc\Micro\Exception' with message 'The Not-Found handler is not callable or is not defined' in C:\wamp\www\my-rest-api\index.php on line 177 ( ! ) Phalcon\Mvc\Micro\Exception: The Not-Found handler is not callable or is not defined in C:\wamp\www\my-rest-api\index.php on line 177

On line 177 code line is

$app->handle();
2
Maybe you should add things like error messages or log messages to your question. - TheGreenkey
@thegreenkey i have update my question - user4703357
probably you should put your code on github to let somebody find whats wrong. - yergo

2 Answers

2
votes

I had the identical problem. In my case this was fixed by

  • Ensuring rewrite was working (as Erick said)
  • Ensuring files were in a directory my-rest-api underneath the web root
  • Additionally, changing localhost to 127.0.0.1 in index.php because of a MySQL issue
  • Adding the not found route (from https://docs.phalconphp.com/en/latest/reference/micro.html)

ie, the following somewhere near the bottom of index.php

$app->notFound(function () use ($app) {
    $app->response->setStatusCode(404, "Not Found")->sendHeaders();
    echo 'This is crazy, but this page was not found!';
});

Hope that helps

Jonathan

1
votes

1) you are probably missing .htaccess file with Apache mod_rewrite on in the same folder of index.php

2) You should declare Not Found route in Router service. This is declared in index.php.