All Projects → BrandEmbassy → slim-nette-extension

BrandEmbassy / slim-nette-extension

Licence: MIT license
Nette Extension for Slim API micro-framework using middlewares.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to slim-nette-extension

Caching
⏱ Caching library with easy-to-use API and many cache backends.
Stars: ✭ 234 (+1276.47%)
Mutual labels:  nette, nette-framework
application
✨ Extra contrib to nette/application (@nette)
Stars: ✭ 23 (+35.29%)
Mutual labels:  nette, nette-framework
Database
💾 A database layer with a familiar PDO-like API but much more powerful. Building queries, advanced joins, drivers for MySQL, PostgreSQL, SQLite, MS SQL Server and Oracle.
Stars: ✭ 251 (+1376.47%)
Mutual labels:  nette, nette-framework
Http
🌐 Abstraction for HTTP request, response and session. Provides careful data sanitization and utility for URL and cookies manipulation.
Stars: ✭ 223 (+1211.76%)
Mutual labels:  nette, nette-framework
web-project
Standard Web Project: a simple skeleton application using the Nette
Stars: ✭ 88 (+417.65%)
Mutual labels:  nette, nette-framework
Datagrid
💪 DataGrid for Nette Framework: filtering, sorting, pagination, tree view, table view, translator, etc
Stars: ✭ 224 (+1217.65%)
Mutual labels:  nette, nette-framework
examples
🎓 Examples demonstrating the Nette Framework.
Stars: ✭ 89 (+423.53%)
Mutual labels:  nette, nette-framework
Sandbox
Nette Framework sandbox project.
Stars: ✭ 143 (+741.18%)
Mutual labels:  nette, nette-framework
apitte-openapi
👪 OpenAPI specification for Apitte stack
Stars: ✭ 15 (-11.76%)
Mutual labels:  nette, nette-framework
event-dispatcher
💥 Best events support (symfony/event-dispatcher) to Nette Framework (@nette)
Stars: ✭ 23 (+35.29%)
Mutual labels:  nette, nette-framework
Application
🏆 A full-stack component-based MVC kernel for PHP that helps you write powerful and modern web applications. Write less, have cleaner code and your work will bring you joy.
Stars: ✭ 205 (+1105.88%)
Mutual labels:  nette, nette-framework
fileupload
🆙 File uploads on steroids for Nette Framework (@nette). Implements blueimp/jquery-file-upload.
Stars: ✭ 28 (+64.71%)
Mutual labels:  nette, nette-framework
Security
🔑 Provides authentication, authorization and a role-based access control management via ACL (Access Control List)
Stars: ✭ 180 (+958.82%)
Mutual labels:  nette, nette-framework
NiftyGrid
DataGrid for Nette Framework
Stars: ✭ 34 (+100%)
Mutual labels:  nette, nette-framework
Nette.ajax.js
Flexible AJAX for Nette Framework. Supports snippets, redirects etc.
Stars: ✭ 150 (+782.35%)
Mutual labels:  nette, nette-framework
dockerfiles
🐳 Dockerfiles for Nette Framework. Nette in Docker. (@nette)
Stars: ✭ 15 (-11.76%)
Mutual labels:  nette, nette-framework
Component Model
⚛ Component model foundation for Nette.
Stars: ✭ 117 (+588.24%)
Mutual labels:  nette, nette-framework
Tokenizer
Source code tokenizer
Stars: ✭ 119 (+600%)
Mutual labels:  nette, nette-framework
nette-minified
[DISCONTINUED] Minified version of Nette Framework.
Stars: ✭ 16 (-5.88%)
Mutual labels:  nette, nette-framework
image-storage
🌠 Image storage for Nette framework
Stars: ✭ 27 (+58.82%)
Mutual labels:  nette, nette-framework

CircleCI Total Downloads Latest Stable Version

Nette Extension for integration of SLIM for API

This extension brings the power of Slim for applications using Nette DI. It enables you to easily work with Slim middleware stack and develop your API easily.

The general idea has been discussed in this article. (Czech language)

Philosophy

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.

Easy configuration

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

Usage

So let's start!

composer require brandembassy/slim-nette-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

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.

parameters:
    api:
        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:
            new-api: # This is name of your API
                "2.0": # Version of your API
                    '/channels': # Matched URL will be "your-domain.org/new-api/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. 
                            middleware:
                                - 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\SomeBeforeRequestMiddleware 
            
        beforeRequestMiddlewares:
            # this is called for each request, even when route does NOT exist (404 requests)
            - App\SomeBeforeRouteMiddleware tests/Dummy/BeforeRequestMiddleware.php

You can also reference the named service by it's name.

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

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);
$factory->create()->run();
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].