Bravo Kernel Home Archives Feed

Search
 May 16 2015
 Apr 12 2015
 Improve on Github
How to build a CakePHP 3 REST API in minutes
Tag Cloud
Step-by-step instructions for creating a full featured RESTful API using CakePHP 3.

api apple cakephp cakephp3
Before We Begin
chef chef-dk cocktails composer

This is part one of the CakePHP 3 REST API tutorial series:
database debian dns dutch

elasticsearch fim foc git github ipad
1. How to build a CakePHP 3 REST API in minutes
iphone javascript jwt kitchen logstash
2. How to use a CakePHP 3 REST API
microsoft minecraft misc mobile
3. How to prefix route a CakePHP 3 REST API
4. How to add JWT Authentication to a CakePHP 3 REST API mssql nginx octopress

octostrap3 php phpcs rest
1. Create The Application security shellshock time ubuntu

vagrant validator wheezy xdebug

For this tutorial (and the follow-up posts) we will create a fresh CakePHP 3 application
for our API:

named cake3api.app
connected to a database named cake3api_app
exposed using virtualhost http://cake3api.app

If you need help with the installation either:

This PDF was generated via the PDFmyURL web conversion service!

. Add the CRUD plugin Add the CRUD plugin to your application so your API will benefit of additional functionality like pagination. To prepare for the follow-up tutorial we will enable the CocktailsController by using the resources() method inside the / scope definition of your config/routes. follow the detailed installation instructions of the CakePHP Blog Tutorial install cakebox and run cakebox application add cake3api.0 Now run the following command to make your application use the plugin: 1 bin/cake plugin load Crud 3.. 3 . function ($routes $routes)) { 2 $routes->resources( $routes ->resources('Cocktails' 'Cocktails'). Enable the API a) Expose one or more controllers Only controllers explicitly enabled for API use will be accessible through your API. ). Run the following command inside your application’s root directory to composer install the plugin: 1 composer require friendsofcake/crud:~4. 4 } This PDF was generated via the PDFmyURL web conversion service! .0 friendsofcake/crud:~4..app to set up the application. database and virtual host 2. thin controllers and DRY best practices.php file like this: 1 Router::scope('/' Router::scope('/'.

Delete' 19 ]. 27 } This PDF was generated via the PDFmyURL web conversion service! . 'RequestHandler' 12 'Crud. 5 6 class AppController extends Controller { 7 8 use \Crud Crud\Controller Controller\ControllerTrait ControllerTrait.ApiQueryLog' 24 ] 25 ] 26 ]. 9 10 public $components = [ 11 'RequestHandler'..View'..Add' 17 'Crud.Crud' => [ 13 'actions' => [ 14 'Crud.Api' 22 'Crud..Index' 15 'Crud.Edit'.Add'. 4 } b) Configure the API Make the default API configuration available to all controllers in your application by replacing the content of your src/Controller/AppController..View' 16 'Crud.Index'.. 'Crud... 'Crud.. 'Crud.. 'Crud. 'Crud.ApiPagination'. 'Crud.ApiPagination' 23 'Crud.Edit' 18 'Crud. 3 4 use Cake Cake\Controller Controller\Controller Controller.Api'.. 20 'listeners' => [ 21 'Crud.php file with: 1 <?php 2 namespace App App\Controller Controller.

4 ""code code": ": 404 5 } Quite impressive but in all fairness… even though you now have a (very) cool API that only took minutes to create it is still pretty useless without any meaningful data to serve so this might be a good moment to dive straight into the follow-up tutorial: How to use a CakePHP3 REST API Additional reading This PDF was generated via the PDFmyURL web conversion service! ..json and . 3 ""url url": ": "\/index. c) Optionally enable extensions Exposing your API resources requires no additional configuration.xml extensions so open your config/routes.".php file and add the following line directly above the / scope definition: 1 Router::extensions(['json' Router::extensions(['json'.".json and be presented with your API’s first JSON (error) response looking like this: 1 { 2 ""message message": ": "Controller class Index could not be found. they are already fully accessible using Request Headers. ]). Stop The Clock! That’s all. However… we will assume you want to additionally allow access to your API resources using the . found. you should now be able to browse to http://cake3api.. 'xml' 'xml']).json".app/index.json" "\/index.

Setup your Service Desk in 2 mins! Comments © 2015 bravo-kernel This PDF was generated via the PDFmyURL web conversion service! .  CakePHP  api. Efficient & ITIL-ready. cakephp3. rest Support this blog Service Desk Software Simple. cakephp. Follow-up tutorial “How to use a CakePHP3 REST API“ End-state application sources for this tutorial FriendsOfCake CRUD plugin documentation The CakePHP 3 Book and CakePHP 3 API documentation Hat tip to CakePHP Core Developers jose_zap and ADmad for helping create this post.