infotechnohelp/cakephp-api-handler

Plugin for CakePHP 3

Installs: 1 271

Dependents: 2

Suggesters: 0

Security: 0

Stars: 0

Forks: 1

Type:cakephp-plugin

1.0.12 2019-03-08 14:49 UTC

This package is auto-updated.

Last update: 2024-04-09 02:00:10 UTC


README

Set up

Manually add to APP/config/bootstrap.php

Plugin::load('ApiHandler', ['routes' => true]);

or use command

bin/cake plugin load ApiHandler -r

Replace manually in APP/src/Application.php

use Cake\Error\Middleware\ErrorHandlerMiddleware;use ApiHandler\Middleware\ErrorHandlerMiddleware;

Usage

API layer

Create Api Controller

Path: APP/src/Controller/Api

namespace App\Controller\Api;

use ApiHandler\Traits\ApiController;

class MyController extends AppContoller
{
    use ApiController;
    
    public function get()
    {
        $this->_setResponse([1, 2, 3]);
    }
}

Response structure

{ "data": {"1", "2", "3"}, "code": 200, message": null }

In case of exception message has a value (Exception message), data is null

Send requests

Prefix api/

In order to send request to APP/src/Controller/Api/MyController→get(), use this path:

api/my/get