Cakephp is one of my favorite framework, and with the time Cakephp improve and add lots of new feature in it and made easy to develop large scale application. In my last post i explain how to setup your Cakephp application. Now in this post i am going to explain how we can create web service in Cakephp in few minutes.Web services in cakephp 3

Before we start building our first web service in Cakephp i hope you already setup you Cakephp  and  your web app is working with some raw data for testing.

if not then it’s okay you can bake your cake with few command as shown in video. Please follow video to understand and demonstrate what we actually going to make. For this post i have a user table in which i can perform CURD operation using CakePHP REST API.

Copy above SQL and paste in your database and download sample code from above download link.


Step 1. Now first we can add JSON extension in our routes file so we can load json data from URL,



Step 2. Now in this step we can update in some of method so we can get json response. For this we can remove redirects and flash messages as shown code below

Step 3. After updating your controller you can use any REST Client for this tutorial iam using POSTMAN.

API URL: Paste below url in your rest client and run

GET USER LIST:  http://localhost/cakeservice/users/index.json

GetUserList in cakephp service - trinitytuts

View User: http://localhost/cakeservice/users/view/{user_id}.json

ViewUser cakephp json service - trinitytuts

Edit User: http://localhost/cakeservice/users/edit/{user_id}.json

Edit user info cakephp webservice - trinitytuts

Delete User: http://localhost/cakeservice/users/delete/{user_id}.json

Delete user from rest apr cakephp 3 - trinitytuts

To view its working you can download code from above link or you can view video. This post is very basic and easy for beginners.