PHPackages                             freefri/cake-rest-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. freefri/cake-rest-api

ActiveCakephp-plugin[HTTP &amp; Networking](/categories/http)

freefri/cake-rest-api
=====================

CakePHP Rest API

0.8.4(2w ago)07.5k↓39.8%12MITPHPPHP &gt;=8.3CI passing

Since Jan 13Pushed 1w ago1 watchersCompare

[ Source](https://github.com/freefri/cake-rest-api)[ Packagist](https://packagist.org/packages/freefri/cake-rest-api)[ Docs](https://github.com/freefri/cake-rest-api)[ RSS](/packages/freefri-cake-rest-api/feed)WikiDiscussions main Synced 2d ago

READMEChangelogDependencies (35)Versions (112)Used By (12)

RestApi package for CakePHP
===========================

[](#restapi-package-for-cakephp)

Rest API for CakePHP 5.x

Configuration
-------------

[](#configuration)

- Some configuration can be done using env variables (search for `env(` in the project to find usages).
- Some configuration when working with plugins can be done from the main configuration (`config/app.php` file).

    - Using the key `Swagger` is optional, but can be helpful to customize some directories (search for `read('Swagger` for details)
    - As sibling from the main `App` configuration use the namespace of the plugin followed by the word `Plugin`.

For example, if your plugin namespace is called Example, create the following config file:

```
return [
    'debug' => false,
    'App' => [ ... ],
    'Swagger' => [ ... ]
    'ExamplePlugin' => [
        'tablePrefix' => 'example_',
        'routePath' => '/api/v1',
        'routePath2' => '/api/v2',
    ],
];

```

The following configuration can be used:

- `tablePrefix`: (optional) in case you want to add a prefix for you database tables, e.g. `myplugin_users`. Can be empty string.
- `routePath`: Definition for the beginning of the path for all routes in the plugin
- `routePath2`: (optional) a second path prefix under which all the plugin routes are additionally registered, e.g. to expose the same routes under both `/api/v1` and `/api/v2`. When empty or not set, only `routePath` is used.

Swagger
-------

[](#swagger)

In order to make swagger UI with openapi description available, a new controller `SwaggerJsonController` must be created, with the corresponding route definition. The method `getContent` can be overwritten in this controller in order to add customization for the main spec info (title, description, version, etc.). Swagger generation can be configured as described in the Configuration section above.

In any controller test the function `$this->skipNextRequestInSwagger()` can be used to do not add the next request.

### Swagger configuration keys

[](#swagger-configuration-keys)

All of the following live under the `Swagger` key in `config/app.php` (read via `Configure::read('Swagger.*')`). Every key is optional and falls back to a sensible default when not set.

- `readerClass`: Fully qualified class name of the reader used to build the spec. Default: `\RestApi\Lib\Swagger\FileReader\SwaggerReader`.
- `apiVersion`: Version string shown under `info.version` in the generated spec. Default: an auto-generated, date-based version (e.g. `9.24.121530`).
- `jsonDir`: Directory where the generated json spec files are stored and read from. Default: `ROOT//`.
- `fullFileDir`: Directory where the single combined (full) json spec is written. When `null`, falls back to the `SWAGGER_RELATIVE_FILE_DIR` env variable (appended to `ROOT`); when `false` or empty the full file is not generated; when `true` (or `'1'`) the default `jsonDir` is used.
- `fullFileName`: File name for the combined full json spec. When empty, falls back to the `SWAGGER_FULL_FILE_NAME` env variable, then to the built-in default (`SwaggerReader::FULL_SWAGGER_JSON`).
- `identifyEntities`: Boolean. When truthy, entities expose their class name as a virtual field in the serialized output (used to identify entity types in the spec).
- `displayErrorResponses`: Boolean. When falsy (default), non-success responses (status codes outside 200–399) are removed from the spec; set truthy to keep error responses.
- `displayMethodsWithoutOk`: Boolean. When falsy (default), methods that have no success (200–399) response are removed from the spec; set truthy to keep them.
- `addRoutePrefix`: String prepended to every route path collected for the spec.
- `acceptLanguage`: Description (or value) for the `Accept-Language` header in generated requests. When `false` the header is omitted; when empty a default descriptive string is used.

### Swagger environment variables

[](#swagger-environment-variables)

Some Swagger behaviour is configured via environment variables (`getenv`) instead of `config/app.php`:

- `SWAGGER_NAMESPACE_TO_REMOVE` (and `SWAGGER_NAMESPACE_TO_REMOVE_1` … `SWAGGER_NAMESPACE_TO_REMOVE_20`): Namespace prefixes to strip from generated type/schema names. When building a type name the entity class name has `Model\Entity\` removed and every remaining `\` replaced with `Ns`, so e.g. `RestApi\Model\Entity\LogEntry` becomes `RestApiNsLogEntry`. Setting `SWAGGER_NAMESPACE_TO_REMOVE=RestApi` strips the `RestApi\` prefix first, yielding just `LogEntry`. Note this only removes leading namespace prefixes, e.g. `SWAGGER_NAMESPACE_TO_REMOVE=Course` turns `CourseNsRanking` (from `Course\Ranking`) into `Ranking`. Up to 21 values can be configured (the unsuffixed key plus suffixes `_1` through `_20`).
- `SWAGGER_RELATIVE_FILE_DIR`: Fallback directory for the combined full json spec, appended to `ROOT`. Only used when `Swagger.fullFileDir` is `null`.
- `SWAGGER_FULL_FILE_NAME`: Fallback file name for the combined full json spec. Only used when `Swagger.fullFileName` is empty (before falling back to the built-in `FULLswagger.json`).

Logs in database
----------------

[](#logs-in-database)

Logs in database can be easily enabled.

Just add to the `Log` section in `config/app.php` the className `\RestApi\Lib\DatabaseLog::class` and add a migration with phinx:

```
$this->table('log_entries', ['collation' => 'utf8mb4_general_ci', 'id' => false])
    ->addColumn('id', 'biginteger', [
        'autoIncrement' => true,
        'default' => null,
        'limit' => null,
        'null' => false,
        'signed' => false,
    ])
    ->addPrimaryKey(['id'])
    ->addColumn('type', 'string', [
        'default' => null,
        'limit' => 50,
        'null' => true,
    ])
    ->addColumn('title', 'string', [
        'default' => null,
        'limit' => 30,
        'null' => true,
    ])
    ->addColumn('message', 'text', [
        'default' => null,
        'limit' => null,
        'null' => true,
    ])
    ->addColumn('environment', 'string', [
        'default' => null,
        'limit' => 100,
        'null' => true,
    ])
    ->addColumn('server', 'text', [
        'default' => null,
        'limit' => null,
        'null' => true,
    ])
    ->addColumn('created', 'datetime', [
        'default' => null,
        'limit' => null,
        'null' => true,
    ])
    ->addIndex(
        [
            'created',
        ]
    )
    ->create();

```

License
-------

[](#license)

The source code for the site is licensed under the **MIT license**, which you can find in the [LICENSE](../LICENSE/) file.

###  Health Score

54

—

FairBetter than 96% of packages

Maintenance97

Actively maintained with recent releases

Popularity24

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 93.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~8 days

Recently: every ~1 days

Total

111

Last Release

16d ago

PHP version history (6 changes)0.1.0PHP &gt;=7.3

0.2.1PHP &gt;=7.4

0.5.17PHP &gt;=7.4 || &gt;=8.0

0.6.6PHP &gt;=8.0

0.8.0PHP &gt;=8.1

0.8.2PHP &gt;=8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2754631?v=4)[freefri](/maintainers/freefri)[@freefri](https://github.com/freefri)

---

Top Contributors

[![freefri](https://avatars.githubusercontent.com/u/2754631?v=4)](https://github.com/freefri "freefri (222 commits)")[![pnordev](https://avatars.githubusercontent.com/u/164324342?v=4)](https://github.com/pnordev "pnordev (15 commits)")

---

Tags

apirestcakephp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/freefri-cake-rest-api/health.svg)

```
[![Health](https://phpackages.com/badges/freefri-cake-rest-api/health.svg)](https://phpackages.com/packages/freefri-cake-rest-api)
```

###  Alternatives

[cakephp/debug_kit

CakePHP Debug Kit

86314.7M171](/packages/cakephp-debug-kit)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M574](/packages/shopware-core)[mixerapi/mixerapi

Streamline development of API-first applications in CakePHP

4443.7k](/packages/mixerapi-mixerapi)[cakedc/cakephp-api

Api plugin for CakePHP

61114.0k](/packages/cakedc-cakephp-api)[andrej-griniuk/cakephp-fractal-transformer-view

CakePHP view builder utilizing Fractal library for entities transformation

1891.9k](/packages/andrej-griniuk-cakephp-fractal-transformer-view)[sprintcube/cakephp-rest

Rest API plugin for CakePHP 3

256.8k](/packages/sprintcube-cakephp-rest)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
