/crud-json-api

CakePHP Crud Listener for building JSON API compliant APIs

Primary LanguagePHPMIT LicenseMIT

Build Status Coverage Status Total Downloads Latest Stable Version Documentation Status

JSON API Crud Listener for CakePHP

Crud Listener for (rapidly) building CakePHP APIs following the JSON API specification.

Documentation

Documentation found here.

Installation

composer require friendsofcake/crud-json-api

Why use it?

  • standardized API data fetching, data posting and (validation) errors
  • automated handling of complex associations/relationships
  • instant compatibility with JSON API supporting tools like Ember Data
  • tons of configurable options to manipulate the generated json

Sample output

  {
    "data": {
      "type": "countries",
      "id": "2",
      "attributes": {
        "code": "BE",
        "name": "Belgium"
      },
      "relationships": {
        "currency": {
          "data": {
            "type": "currencies",
            "id": "1"
          },
          "links": {
            "self": "/currencies/1"
          }
        },
        "cultures": {
          "data": [
            {
              "type": "cultures",
              "id": "2"
            },
            {
              "type": "cultures",
              "id": "3"
            }
          ],
          "links": {
            "self": "/cultures?country_id=2"
          }
        }
      },
      "links": {
        "self": "/countries/2"
      }
    },
    "included": [
      {
        "type": "currencies",
        "id": "1",
        "attributes": {
          "code": "EUR",
          "name": "Euro"
        },
        "links": {
          "self": "/currencies/1"
        }
      },
      {
        "type": "cultures",
        "id": "2",
        "attributes": {
          "code": "nl-BE",
          "name": "Dutch (Belgium)"
        },
        "links": {
          "self": "/cultures/2"
        }
      },
      {
        "type": "cultures",
        "id": "3",
        "attributes": {
          "code": "fr-BE",
          "name": "French (Belgium)"
        },
        "links": {
          "self": "/cultures/3"
        }
      }
    ]
  }

Contribute

Before submitting a PR make sure: