PUT and DELETE methods not found.

On my begginer steps with phalcon I am struggling with strange issue. Building REST Api I was able to work with GET and POST methods.

For example:

$app->get('/', function () { echo 'REST Api @Phalcon ' . Phalcon\Version::get(); });

However when trying to access PUT:

$app->put('/test/{id}' , function($id) use ($app) { echo $id; });

or DELETE:

$app->delete('/test/{id}' , function($id) use ($app) { echo $id; });

I'm getting stuck with 404 errors.

I'm not sure if those errors comes from bad configuration, wrong code just or Phalcon itself. I would appreciate any help.

Whole code is available on: https://github.com/Wampirue/phalcon-rest/tree/dev Application is available on-line at: http://rest.encrypted.pl



33.1k

Thanks for your response, but I dont think that this is causing any problems. I used

echo 1;

to simplify code. I've changed code as you requested (updated repo) to

PUT:

$app->put('/test/{id}' , function($id) use ($app) { $app->response->setJsonContent(array('status' => 'OK', 'data' => $id)); return $app->response; });

DELETE:

$app->delete('/test/{id}' , function($id) use ($app) { $response = new Phalcon\Http\Response(); $response->setJsonContent(array('status' => 'OK', 'data' => $id)); return $response; });

And none is working.



33.1k

Hey man

I test your code on my server(Nginx) and it woking, here result

# curl -i -X GET http://support.dev/
HTTP/1.1 200 OK
Server: nginx/1.6.2
Date: Tue, 14 Apr 2015 09:40:02 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/5.6.5

REST Api @Phalcon 1.3.4root at startupvn in /usr/share/nginx/html/phalcon-rest on master*
# curl -i -X DELETE http://support.dev/test/1
HTTP/1.1 200 OK
Server: nginx/1.6.2
Date: Tue, 14 Apr 2015 09:40:14 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/5.6.5

{"status":"OK","data":"1"}root at startupvn in /usr/share/nginx/html/phalcon-rest on master*
#

May be config apache2 to do confuse ?

edited Aug '15

Its been while from your answer Thien, but you helped me a lot, saying that code actually works. For those folks stuck like me: Ive got default override of .htaccess and it finally starts working after adding:

<Limit PUT DELETE>
Allow from all
#Deny from all
</Limit>