2017 © Pedro Peláez
 

cakephp-plugin cakephp-api

image

berrygoudswaard/cakephp-api

  • Thursday, May 24, 2018
  • by berrygoudswaard
  • Repository
  • 2 Watchers
  • 0 Stars
  • 940 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 8 % Grown

The README.md

CakePHP API Component

This plugin contains a component that make it easier to create API output with CakePHP, (*1)

Requirements

  • CakePHP 3.1+

Installation

composer require berrygoudswaard/cakephp-api

Usage

In your app's config/bootstrap.php add:, (*2)

Plugin::load('BerryGoudswaard/Api');

Then load the component where you need it by adding the following code to your controller:, (*3)

$this->loadComponent('BerryGoudswaard/Api.Api', [
    'cors' => [
        'allowHeaders' => ['Content-Type', 'Authorization'],
        'allowMethods' => ['GET', 'POST', 'PUT', 'DELETE'],
        'allowOrigins' => ['http://localhost:4200', 'http://www.berrygoudswaard.nl'],
        'allowCredentials' => 'true',
    ]
]);

Output data

public function index()
{
    $tags = $this->Tags->find();

    $this->Api->addData('tags', $tags);
    return $this->Api->output();
}

The code above will output something like:, (*4)

{
    "message": "OK",
    "code": 200,
    "data": {
        "tags": {
            "items": [
                {
                    "id": 1,
                    "tag": "cakephp"
                }, {
                    "id": 2,
                    "tag": "plugin"
                }
            ]
        }
    }
}

The Versions

24/05 2018

dev-master

9999999-dev

  Sources   Download

MIT

by Berry Goudswaard

api cakephp

24/05 2018

0.1.0

0.1.0.0

  Sources   Download

MIT

by Berry Goudswaard

api cakephp

08/09 2017

0.0.2

0.0.2.0

  Sources   Download

MIT

by Berry Goudswaard

api cakephp

08/09 2017

0.0.3

0.0.3.0

  Sources   Download

MIT

by Berry Goudswaard

api cakephp

27/07 2017

0.0.1

0.0.1.0

  Sources   Download

MIT

by Berry Goudswaard

api cakephp