PHPackages                             apitte/core - 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. apitte/core

Abandoned → [contributte/apitte](/?search=contributte%2Fapitte)ArchivedLibrary[HTTP &amp; Networking](/categories/http)

apitte/core
===========

Core API library in Apitte stack

v0.8.1(4y ago)4451.0k—8.4%57MITPHPPHP &gt;=7.3

Since Nov 23Pushed 5mo ago2 watchersCompare

[ Source](https://github.com/contributte/apitte-core)[ Packagist](https://packagist.org/packages/apitte/core)[ Docs](https://github.com/apitte/core)[ Fund](https://contributte.org/partners.html)[ GitHub Sponsors](https://github.com/f3l1x)[ RSS](/packages/apitte-core/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (15)Versions (12)Used By (7)

[![](https://camo.githubusercontent.com/6b8da235bb0ef4bf7a50fc531ca345215b29014ab2ce4ae8f2628021853bb2e7/68747470733a2f2f686561746261646765722e76657263656c2e6170702f6769746875622f726561646d652f636f6e74726962757474652f6170697474652d636f72652f3f646570726563617465643d31)](https://camo.githubusercontent.com/6b8da235bb0ef4bf7a50fc531ca345215b29014ab2ce4ae8f2628021853bb2e7/68747470733a2f2f686561746261646765722e76657263656c2e6170702f6769746875622f726561646d652f636f6e74726962757474652f6170697474652d636f72652f3f646570726563617465643d31)

 [![](https://camo.githubusercontent.com/a8b1cd856d7d396fdebbe46947cc3507490acc267a02361e5e53bb7b820c95c3/68747470733a2f2f62616467656e2e6e65742f62616467652f737570706f72742f6769747465722f6379616e)](https://bit.ly/ctteg) [![](https://camo.githubusercontent.com/86d6416fc04f8bcc3daa7bf881526b9953b9726b1164d05c157c8713e3a73418/68747470733a2f2f62616467656e2e6e65742f62616467652f737570706f72742f666f72756d2f79656c6c6f77)](https://bit.ly/cttfo) [![](https://camo.githubusercontent.com/5d170ab94e6d594609561e16fe0f9e4293968fbd4dfcfafc5e11efc1415ef09c/68747470733a2f2f62616467656e2e6e65742f62616467652f73706f6e736f722f646f6e6174696f6e732f463936383534)](https://contributte.org/partners.html)

 Website 🚀 [contributte.org](https://contributte.org) | Contact 👨🏻‍💻 [f3l1x.io](https://f3l1x.io) | Twitter 🐦 [@contributte](https://twitter.com/contributte)

Disclaimer
----------

[](#disclaimer)

⚠️This project is no longer being maintained. Please use [contributte/apitte](https://github.com/contributte/apitte).Composer[`apitte/core`](https://packagist.org/packages/apitte/core)Version[![](https://camo.githubusercontent.com/b97342ed71e382e70630144f79c1975ba60081d86dcb8002f2eb875f4b684ca2/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f762f6170697474652f636f7265)](https://camo.githubusercontent.com/b97342ed71e382e70630144f79c1975ba60081d86dcb8002f2eb875f4b684ca2/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f762f6170697474652f636f7265)PHP[![](https://camo.githubusercontent.com/247f69806582a0fe0d0fb4915cb4bb613b6609ada17aaa26b518456815146de0/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f7068702f6170697474652f636f7265)](https://camo.githubusercontent.com/247f69806582a0fe0d0fb4915cb4bb613b6609ada17aaa26b518456815146de0/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f7068702f6170697474652f636f7265)License[![](https://camo.githubusercontent.com/27acd958fd99b0aa57ebbba49585e04c51a073d0c4bc47182fc832a95e170ff5/68747470733a2f2f62616467656e2e6e65742f6769746875622f6c6963656e73652f636f6e74726962757474652f6170697474652d636f7265)](https://camo.githubusercontent.com/27acd958fd99b0aa57ebbba49585e04c51a073d0c4bc47182fc832a95e170ff5/68747470733a2f2f62616467656e2e6e65742f6769746875622f6c6963656e73652f636f6e74726962757474652f6170697474652d636f7265)Usage
-----

[](#usage)

To install the latest version of `apitte/core` use [Composer](https://getcomposer.org).

```
composer require apitte/core
```

Documentation
-------------

[](#documentation)

Core library of Apitte API framework.

### Setup

[](#setup)

Install core

```
composer require apitte/core
```

Register DI extension

```
extensions:
    api: Apitte\Core\DI\ApiExtension

api:
    debug: %debugMode%
    catchException: true # Sets if exception should be catched and transformed into response or rethrown to output (debug only)
```

Create entry point

```
// www/index.php

use Apitte\Core\Application\IApplication;
use App\Bootstrap;

require __DIR__ . '/../vendor/autoload.php';

Bootstrap::boot()
    ->createContainer()
    ->getByType(IApplication::class)
    ->run();
```

#### Usage in combination with nette application

[](#usage-in-combination-with-nette-application)

```
// www/index.php

use Apitte\Core\Application\IApplication as ApiApplication;
use App\Bootstrap;
use Nette\Application\Application as UIApplication;

require __DIR__ . '/../vendor/autoload.php';

$isApi = substr($_SERVER['REQUEST_URI'], 0, 4) === '/api';
$container = Bootstrap::boot()->createContainer();

if ($isApi) {
    $container->getByType(ApiApplication::class)->run();
} else {
    $container->getByType(UIApplication::class)->run();
}
```

### Endpoints

[](#endpoints)

Endpoint is representation of a unique url (like a `/api/v1/users`) and one or multiple operations (HTTP methods).

In our case endpoint is implemented as a controller method.

#### Controllers

[](#controllers)

Create base controller with root path to your api

- controller must implement `Apitte\Core\UI\Controller\IController`

```
namespace App\Api\V1\Controllers;

use Apitte\Core\Annotation\Controller\Path;
use Apitte\Core\UI\Controller\IController;

/**
 * @Path("/api/v1")
 */
abstract class BaseV1Controller implements IController
{
}
```

Create an endpoint

- Controller must have annotation `@Path()` and be registered as service
- Method must have annotations `@Path()` and `@Method()`

```
services:
    - App\Api\V1\Controllers\UsersController
```

```
namespace App\Api\V1\Controllers;

use Apitte\Core\Annotation\Controller\Method;
use Apitte\Core\Annotation\Controller\Path;
use Apitte\Core\Http\ApiRequest;
use Apitte\Core\Http\ApiResponse;
use Nette\Utils\Json;

/**
 * @Path("/users")
 */
class UsersController extends BaseV1Controller
{

    /**
     * @Path("/")
     * @Method("GET")
     */
    public function index(ApiRequest $request, ApiResponse $response): ApiResponse
    {
        // This is an endpoint
        //  - its path is /api/v1/users/
        //  - it should be available on address example.com/api/v1/users/

        $response = $response->writeBody(Json::encode([
            [
                'id' => 1,
                'firstName' => 'John',
                'lastName' => 'Doe',
                'emailAddress' => 'john@doe.com',
            ],
            [
                'id' => 2,
                'firstName' => 'Elon',
                'lastName' => 'Musk',
                'emailAddress' => 'elon.musk@spacex.com',
            ],
        ]));

        return $response;
    }

}
```

#### List of annotations / attributes

[](#list-of-annotations--attributes)

> You can use seamless PHP 8 attributes.

`@Id`

- Must consist only of following characters: `a-z`, `A-Z`, `0-9`, `_`
- Not used by Apitte for anything, it may just help you identify, group, etc. your endpoints

`@Path`

- Must consist only of following characters: `a-z`, `A-Z`, `0-9`, `-_/`
- The `@Path` annotation can be used on:
    - abstract controller to define a group path for multiple controllers (e.g. `example.com/v1/...`)
    - final controller to define a path for that particular controller (e.g. `example.com/v1/users`)
    - method to define a path for a specific endpoint
- This hierarchy is then used to build the schema and make routing possible.

`@Method`

- Allowed HTTP method for endpoint
- GET, POST, PUT, OPTION, DELETE, HEAD
- `@Method("GET")`
- `@Method({"POST", "PUT"})`
- Defined on method

`@Tag`

- Used by OpenApi
- Could by also used by your custom logic
- `@Tag(name="name")`
- `@Tag(name="string", value="string|null")`
- Defined on class and method

### Mapping

[](#mapping)

Validate and map data from request and map data to response.

#### Setup

[](#setup-1)

```
api:
    plugins:
        Apitte\Core\DI\Plugin\CoreMappingPlugin:
```

Ensure you have also decorator plugin registered, mapping is implemented by decorators.

#### RequestParameters

[](#requestparameters)

Validate request parameters and convert them to correct php datatype.

```
namespace App\Api\V1\Controllers;

use Apitte\Core\Annotation\Controller\Method;
use Apitte\Core\Annotation\Controller\Path;
use Apitte\Core\Annotation\Controller\RequestParameters;
use Apitte\Core\Annotation\Controller\RequestParameter;
use Apitte\Core\Http\ApiRequest;
use Apitte\Core\Http\ApiResponse;

/**
 * @Path("/users")
 */
class UsersController extends BaseV1Controller
{

    /**
     * @Path("/{id}")
     * @Method("GET")
     * @RequestParameters({
     *      @RequestParameter(name="id", type="int", description="My favourite user ID")
     * })
     */
    public function detail(ApiRequest $request): ApiResponse
    {
        /** @var int $id Perfectly valid integer */
        $id = $request->getParameter('id');

        // Return response with error or user
    }

}
```

#### RequestBody

[](#requestbody)

Use value objects for request body mapping:

```
namespace App\Api\Entity\Request;

use Apitte\Core\Mapping\Request\BasicEntity;

final class UserFilter extends BasicEntity
{

    /**  @var int */
    public $userId;

    /**  @var string */
    public $email;

}
```

```
/**
 * @Path("/filter")
 * @Method("GET")
 * @RequestBody(entity="App\Api\Entity\Request\UserFilter")
 */
public function filter(ApiRequest $request)
{
    /** @var UserFilter $entity */
    $entity = $request->getEntity();
}
```

### Decorators

[](#decorators)

Decorators are used for transformations of request before it is passed into endpoint and for transformations of response after it is returned from endpoint.

#### Setup

[](#setup-2)

```
api:
    plugins:
        Apitte\Core\DI\Plugin\CoreDecoratorPlugin:
```

#### Register decorators

[](#register-decorators)

```
services:
    decorator.request.authentication:
        class: App\Api\Decorator\ExampleResponseDecorator
        tags: [apitte.core.decorator: [priority: 50]]
```

### Router

[](#router)

Checks if an endpoint from schema matches request.

#### SimpleRouter

[](#simplerouter)

Default implementation of router which matches endpoint by URI and by HTTP method.

Requires each endpoint to have an unique combination of URI and HTTP method.

If an endpoint for given URI exists but not for given HTTP method then `405 Method Not Allowed` is returned.

### Errors

[](#errors)

To display errors to user use our prepared `ApiException`, specifically:

- `ClientErrorException` for user errors (400-499)
- `ServerErrorException` for server errors (500-599)

#### SimpleErrorHandler

[](#simpleerrorhandler)

Default error handler transforms error into json response:

```
{
  "status": "error",
  "code": 500,
  "message": "Application encountered an internal error. Please try again later.",
  "context": []
}
```

### Examples

[](#examples)

-  (playground)
-  (more examples)

Version
-------

[](#version)

StateVersionBranchNettePHPstable`^0.8``master`3.0+`>=7.3`stable`^0.5``master`2.4`>=7.1`Development
-----------

[](#development)

This package was maintained by these authors.

[ ![](https://avatars2.githubusercontent.com/u/538058?v=3&s=80)](https://github.com/f3l1x)---

Consider to [support](https://contributte.org/partners.html) **contributte** development team. Also thank you for using this package.

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance49

Moderate activity, may be stable

Popularity40

Moderate usage in the ecosystem

Community29

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~138 days

Recently: every ~199 days

Total

11

Last Release

1714d ago

PHP version history (6 changes)v0.1PHP &gt;= 5.6

v0.4PHP &gt;= 7.1

v0.5PHP &gt;=7.1

v0.6.0PHP ^7.2

v0.7.0PHP &gt;=7.2

v0.8.0PHP &gt;=7.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/538058?v=4)[Milan Šulc](/maintainers/f3l1x)[@f3l1x](https://github.com/f3l1x)

---

Top Contributors

[![mabar](https://avatars.githubusercontent.com/u/20974277?v=4)](https://github.com/mabar "mabar (191 commits)")[![f3l1x](https://avatars.githubusercontent.com/u/538058?v=4)](https://github.com/f3l1x "f3l1x (146 commits)")[![TomasVotruba](https://avatars.githubusercontent.com/u/924196?v=4)](https://github.com/TomasVotruba "TomasVotruba (8 commits)")[![josefbenjac](https://avatars.githubusercontent.com/u/6731626?v=4)](https://github.com/josefbenjac "josefbenjac (8 commits)")[![Roman3349](https://avatars.githubusercontent.com/u/4655467?v=4)](https://github.com/Roman3349 "Roman3349 (5 commits)")[![martenb](https://avatars.githubusercontent.com/u/13311472?v=4)](https://github.com/martenb "martenb (5 commits)")[![vody105](https://avatars.githubusercontent.com/u/22433893?v=4)](https://github.com/vody105 "vody105 (4 commits)")[![kralmichal](https://avatars.githubusercontent.com/u/1733478?v=4)](https://github.com/kralmichal "kralmichal (3 commits)")[![trejjam](https://avatars.githubusercontent.com/u/3594540?v=4)](https://github.com/trejjam "trejjam (3 commits)")[![TonyVlcek](https://avatars.githubusercontent.com/u/4984658?v=4)](https://github.com/TonyVlcek "TonyVlcek (3 commits)")[![miranovy](https://avatars.githubusercontent.com/u/24221737?v=4)](https://github.com/miranovy "miranovy (3 commits)")[![petrparolek](https://avatars.githubusercontent.com/u/6066243?v=4)](https://github.com/petrparolek "petrparolek (3 commits)")[![lulco](https://avatars.githubusercontent.com/u/9377319?v=4)](https://github.com/lulco "lulco (2 commits)")[![woytam](https://avatars.githubusercontent.com/u/12713483?v=4)](https://github.com/woytam "woytam (1 commits)")[![delacry](https://avatars.githubusercontent.com/u/45132928?v=4)](https://github.com/delacry "delacry (1 commits)")[![grossmannmartin](https://avatars.githubusercontent.com/u/1177414?v=4)](https://github.com/grossmannmartin "grossmannmartin (1 commits)")[![kedlas](https://avatars.githubusercontent.com/u/3510893?v=4)](https://github.com/kedlas "kedlas (1 commits)")[![khorsky](https://avatars.githubusercontent.com/u/160295?v=4)](https://github.com/khorsky "khorsky (1 commits)")[![tg666](https://avatars.githubusercontent.com/u/24430186?v=4)](https://github.com/tg666 "tg666 (1 commits)")[![Vlczech](https://avatars.githubusercontent.com/u/10884140?v=4)](https://github.com/Vlczech "Vlczech (1 commits)")

---

Tags

apittecontributtehttpnettephpresthttpapirestnetteannotationapitte

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/apitte-core/health.svg)

```
[![Health](https://phpackages.com/badges/apitte-core/health.svg)](https://phpackages.com/packages/apitte-core)
```

###  Alternatives

[contributte/apitte

An opinionated and enjoyable API framework based on Nette Framework. Supporting content negotiation, debugging, middlewares, attributes and loving openapi/swagger.

641.3M3](/packages/contributte-apitte)[nategood/httpful

A Readable, Chainable, REST friendly, PHP HTTP Client

1.8k17.2M267](/packages/nategood-httpful)[bigcommerce/api

Enables PHP applications to communicate with the Bigcommerce API.

1501.1M8](/packages/bigcommerce-api)[contributte/api

Powerful, documented, validated, built-in API to Nette Framework (@nette)

10684.3k](/packages/contributte-api)[quickbooks/payments-sdk

The Official PHP SDK for QuickBooks Online Payments API

2758.2k2](/packages/quickbooks-payments-sdk)[jsor/hal-client

A lightweight client for consuming and manipulating Hypertext Application Language (HAL) resources.

2425.9k1](/packages/jsor-hal-client)

PHPackages © 2026

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