PHPackages                             brandembassy/slim-nette-extension - 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. [API Development](/categories/api)
4. /
5. brandembassy/slim-nette-extension

ActiveLibrary[API Development](/categories/api)

brandembassy/slim-nette-extension
=================================

6.0.5(3mo ago)19201.2k↓53%2[3 issues](https://github.com/BrandEmbassy/slim-nette-extension/issues)[8 PRs](https://github.com/BrandEmbassy/slim-nette-extension/pulls)MITPHPPHP &gt;=8.2CI failing

Since Mar 17Pushed 2mo ago4 watchersCompare

[ Source](https://github.com/BrandEmbassy/slim-nette-extension)[ Packagist](https://packagist.org/packages/brandembassy/slim-nette-extension)[ RSS](/packages/brandembassy-slim-nette-extension/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (47)Versions (76)Used By (0)

[![CircleCI](https://camo.githubusercontent.com/f3ecf135a5eaf3c2b0e2c4624ae0db70cf74d192fd33ab323888e383489fecd5/68747470733a2f2f636972636c6563692e636f6d2f67682f4272616e64456d62617373792f736c696d2d6e657474652d657874656e73696f6e2e7376673f7374796c653d737667)](https://circleci.com/gh/BrandEmbassy/slim-nette-extension)[![Total Downloads](https://camo.githubusercontent.com/e283333d43b96e8e3d4aa2740934f43097f1322176556276e1a24c1b4e92e55f/68747470733a2f2f706f7365722e707567782e6f72672f4272616e64456d62617373792f736c696d2d6e657474652d657874656e73696f6e2f646f776e6c6f616473)](https://packagist.org/packages/brandembassy/slim-nette-extension)[![Latest Stable Version](https://camo.githubusercontent.com/7c3b1bbc8085d2f9f3c49f02ee88196de4f60556415cc980ba02ac0a94028739/68747470733a2f2f706f7365722e707567782e6f72672f4272616e64456d62617373792f736c696d2d6e657474652d657874656e73696f6e2f762f737461626c65)](https://github.com/BrandEmbassy/slim-nette-extension/releases)

Nette Extension for integration of SLIM for API
===============================================

[](#nette-extension-for-integration-of-slim-for-api)

This extension brings the power of [Slim](https://www.slimframework.com/) for applications using [Nette DI](https://github.com/nette/di). It enables you to easily work with Slim middleware stack and develop your API easily.

**This package now uses Slim Framework 4.x**

The general idea has been discussed in this [article](https://petrhejna.org/blog/api-chain-of-responsibility-approach). (Czech language)

Philosophy
----------

[](#philosophy)

### Single Responsibility

[](#single-responsibility)

The main idea is to delegate responsibilities of the code handling requests to separated middlewares. For example:

- authentication
- validation
- business logic

How middlewares in Slim work is described [here](https://www.slimframework.com/docs/v4/concepts/middleware.html).

### Easy configuration

[](#easy-configuration)

Empowered by Nette DI and it's `neon` configuration syntax this package provides powerful and easy way to define your API.

Usage
-----

[](#usage)

So let's start!

```
composer require brandembassy/slim-nette-extension

```

### Extension

[](#extension)

Now register new extension by adding this code into your `config.neon`:

```
extensions:
    slimApi: BrandEmbassy\Slim\DI\SlimApiExtension # Register extension

slimApi: # Configure it
    slimConfiguration:
        settings:
            removeDefaultHandlers: true # It's recommended to disable original error handling
                                        # and use your own error handlers suited for needs of your app.

    apiDefinitionKey: api # Your API definition will be under this key in "parameters" section.
```

### First API endpoint

[](#first-api-endpoint)

Now let's say you want to make a REST endpoint creating channels, `[POST] /new-api/2.0/channels`

You need to define in `parameters.api` section in `config.neon`.

> **Both services and middlewares must be registered services in DI Container.**

```
slimApi:
    handlers:
        notFound: App\NotFoundHandler # Called when not route isn't matched by URL
        notAllowed: App\NotAllowedHandler # Called when route isn't matched by method
        error: App\ApiErrorHandler # Called when unhandled exception bubbles out

    routes:
        "2.0": # Version of your API
            "channels": # Matched URL will be "your-domain.org/2.0/channels"
                post:
                    # This is service will be invoked to handle the request
                    service: App\CreateChannelAction

                    # Here middleware stack is defined. It's evaluated from bottom to top.
                    middlewares:
                        - App\SomeOtherMiddleware # last in row
                        - App\UsuallyRequestDataValidationMiddleware # second in row
                        - App\SomeAuthMiddleware # this one is called first

    beforeRouteMiddlewares:
        # this is called for each route, before route middlewares
        - App\SomeBeforeRouteMiddleware

    afterRouteMiddlewares:
        # this is called for each route, after the route middlewares
        - App\SomeAfterRouteMiddleware

    beforeRequestMiddlewares:
        # this is called for each request, even when route does NOT exist (404 requests)
        - App\SomeBeforeRequestMiddleware
```

You can also reference the named service by its name.

See `tests/SlimApplicationFactoryTest.php` and `tests/config.neon` for more examples.

### Execution

[](#execution)

Now you can simply get `SlimApplicationFactory` class from your DI Container (or better autowire it), create app and run it.

```
$factory = $container->getByType(SlimApplicationFactory::class);
$app = $factory->create();
$app->run();
```

Migrating from Slim 3 to Slim 4
-------------------------------

[](#migrating-from-slim-3-to-slim-4)

Version 4.x of this package uses Slim Framework 4 instead of Slim Framework 3. The migration should be mostly transparent for users as the package maintains backward compatibility where possible.

### Key Changes

[](#key-changes)

1. **Dependencies**: Slim 4 uses PSR-7, PSR-15, and PSR-17 standards more strictly
2. **Container**: Slim 4 no longer provides its own container, but the package provides a compatibility layer
3. **Middleware**: The double-pass middleware style (`$request, $response, $next`) is still supported
4. **Routing**: Routes are now registered on the App instance directly (handled internally by the package)

### What You Need to Do

[](#what-you-need-to-do)

For most users, the upgrade should be seamless:

1. Update your `composer.json` to require the new version
2. Run `composer update brandembassy/slim-nette-extension`
3. Clear your cache directories (`temp/`, `tests/temp/`)
4. Test your application

### Breaking Changes

[](#breaking-changes)

- `Response` and `ResponseInterface` wrappers have been removed — route handlers now receive a plain PSR-7 `ResponseInterface` directly
- `RequestInterface::getRoute()` now returns `?Route` (nullable)
- `RequestInterface` gained new methods: `getInnerRequest()`, `getRoutingResults()`
- If you were directly accessing Slim internals (like `Slim\Container` or `Slim\Router`), you'll need to update your code
- Custom middleware that relied on Slim 3 specific features may need updates
- `$app->run()` and `$app->handle()` now apply a Content-Type fix for empty responses

### Backward Compatibility

[](#backward-compatibility)

The following are maintained for backward compatibility:

- Middleware signature remains the same (double-pass style `$request, $response, $next`)
- Route handler signature remains the same (`$request, $response`)
- Route and handler registration via NEON configuration is unchanged
- Container access via `$app->getContainer()` works as before

For more details on Slim 4 changes, see the [official Slim 4 upgrade guide](https://www.slimframework.com/docs/v4/start/upgrade.html).

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance80

Actively maintained with recent releases

Popularity42

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity91

Battle-tested with a long release history

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

Recently: every ~2 days

Total

43

Last Release

94d ago

Major Versions

3.0.2 → 4.0.02019-03-16

4.0.5 → 5.0-alpha2020-11-01

4.1 → 5.1-alpha2021-05-14

4.3 → 5.112026-01-27

5.11 → 6.02026-03-23

PHP version history (3 changes)1.0.0PHP &gt;=5.6

3.0.0PHP &gt;=7.2

4.x-devPHP &gt;=8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3398651?v=4)[Jan Veselý](/maintainers/janveselynet)[@janveselynet](https://github.com/janveselynet)

![](https://avatars.githubusercontent.com/u/6583541?v=4)[Dominik Voda](/maintainers/dominikvoda)[@dominikvoda](https://github.com/dominikvoda)

![](https://www.gravatar.com/avatar/505f8fad46cba0f5876182a5d1c498def3024b173f74a424f2c11c43759c1917?d=identicon)[ph-legacy](/maintainers/ph-legacy)

---

Top Contributors

[![dominikvoda](https://avatars.githubusercontent.com/u/6583541?v=4)](https://github.com/dominikvoda "dominikvoda (8 commits)")[![davidpilny](https://avatars.githubusercontent.com/u/17548083?v=4)](https://github.com/davidpilny "davidpilny (7 commits)")[![JanMikes](https://avatars.githubusercontent.com/u/3995003?v=4)](https://github.com/JanMikes "JanMikes (3 commits)")[![yarcheek](https://avatars.githubusercontent.com/u/2684922?v=4)](https://github.com/yarcheek "yarcheek (2 commits)")[![janveselynet](https://avatars.githubusercontent.com/u/3398651?v=4)](https://github.com/janveselynet "janveselynet (2 commits)")[![petrmatulik](https://avatars.githubusercontent.com/u/878253?v=4)](https://github.com/petrmatulik "petrmatulik (2 commits)")[![signor-pedro](https://avatars.githubusercontent.com/u/53906348?v=4)](https://github.com/signor-pedro "signor-pedro (2 commits)")[![nclemons78](https://avatars.githubusercontent.com/u/104171116?v=4)](https://github.com/nclemons78 "nclemons78 (1 commits)")[![podolinek](https://avatars.githubusercontent.com/u/1062993?v=4)](https://github.com/podolinek "podolinek (1 commits)")

---

Tags

apimiddlewarenettenette-dinette-frameworksingle-action-controllerslim

###  Code Quality

TestsPHPUnit

Static AnalysisRector

### Embed Badge

![Health badge](/badges/brandembassy-slim-nette-extension/health.svg)

```
[![Health](https://phpackages.com/badges/brandembassy-slim-nette-extension/health.svg)](https://phpackages.com/packages/brandembassy-slim-nette-extension)
```

###  Alternatives

[cakephp/cakephp

The CakePHP framework

8.9k19.5M1.8k](/packages/cakephp-cakephp)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[thecodingmachine/graphqlite

Write your GraphQL queries in simple to write controllers (using webonyx/graphql-php).

5733.3M47](/packages/thecodingmachine-graphqlite)[typo3/cms-core

TYPO3 CMS Core

3713.2M5.1k](/packages/typo3-cms-core)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[pagemachine/searchable

TYPO3 extension to index and search content with Elasticsearch

1039.9k](/packages/pagemachine-searchable)

PHPackages © 2026

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