Exposing a web service
When you first build an application, you'll most likely imagine how the user will interact with it and how it will be designed and structured for your content and features. However, there also comes a time when you'll want to expose certain functionality of your website as web services.
CakePHP comes well-prepared for this, so in this recipe, we'll look at how you can easily create a data-focused controller to serve certain functionality of your application via a service.
Getting ready
For this recipe, we'll start with a basic controller to serve as our endpoint. So, create a file named ApiController.php
in app/Controller/
with the following content:
<?php App::uses('AppController', 'Controller'); class ApiController extends AppController { }
How to do it...
Perform the following steps:
- Add the following line to your
routes.php
file inapp/Config/
:Router::connect('/api/:object/:command', array( 'controller&apos...