I'm trying to set up and API for a database I maintain through CakePHP. So far I only need access to a single action on a single controller. I have managed to set up a new URL for the POST requests but the original URL still accepts these POSTs too.
Is there a way to stop the POST requests from being accepted by CakePHP unless it is send to the new URL? For example /contact/add is routed to /api/contact and should only accept POST requests there.
In your routes.php
you can configure the routing of contact/add
to api/add
As for the POST data, in your controller method just include something like the following:
public function add() {
if($this->request->is('post')) {
$this->autoRender = false;
//handle api method here
}
else {
//handle other requests here
}
}