PHPackages                             braune-digital/api-base-bundle - 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. braune-digital/api-base-bundle

ActiveSymfony-bundle

braune-digital/api-base-bundle
==============================

Api bundle

v1.1.0(8y ago)02.8kMITPHP

Since Aug 17Pushed 7y ago6 watchersCompare

[ Source](https://github.com/braune-digital/BrauneDigitalApiBaseBundle)[ Packagist](https://packagist.org/packages/braune-digital/api-base-bundle)[ RSS](/packages/braune-digital-api-base-bundle/feed)WikiDiscussions 1.0.x Synced 2mo ago

READMEChangelog (5)Dependencies (4)Versions (9)Used By (0)

BrauneDigitalApiBaseBundle
==========================

[](#braunedigitalapibasebundle)

This Symfony-Bundle uses FOS Rest and provides Basic Api functionality

Features
--------

[](#features)

- BaseApiController: A foundation for your api controllers
- ApiKey authentication: Authenticate users using an api-token
- Pagination
- Query-Filtering: Filter Lists (coming soon)
- Module Access: Split your Api into modules and restrict their access to certain user roles
- Custom Configuration in Response: Add your custom configuration to specific responses

Requirements
------------

[](#requirements)

- FOSRestBundle
- WhiteOctoberPagerFantaBundle
- FOSUserBundle (for now)
- JMSSerializerBundle (optional)

Installation
------------

[](#installation)

### Download using composer:

[](#download-using-composer)

```
composer require braune-digital/api-base-bundle "1.*"
```

### And enable the Bundle in your AppKernel.

[](#and-enable-the-bundle-in-your-appkernel)

You may use the BaseApiController without registering the bundle too.

```
public function registerBundles()
    {
        $bundles = array(
          ...
            new JMS\SerializerBundle\JMSSerializerBundle(),
            new FOS\RestBundle\FOSRestBundle(),

            new BrauneDigital\ApiBaseBundle\BrauneDigitalApiBaseBundle(),
            new Nelmio\CorsBundle\NelmioCorsBundle(),
          ...
        );
```

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

[](#configuration)

### DefaultConfiguration

[](#defaultconfiguration)

```
braune_digital_api_base:
    modules: ~ #Used for Module-Access
    timeout: 0 # Timeout for Api-Tokens (use 0 for no timeout)
    configuration: # Your configuration to be send
```

### FOSRest Configuration

[](#fosrest-configuration)

```
fos_rest:
    disable_csrf_role: ROLE_API
    param_fetcher_listener: true
    body_listener:
        array_normalizer: fos_rest.normalizer.camel_keys
    format_listener: true
    view:
        view_response_listener: force
        exception_wrapper_handler: 'BrauneDigital\ApiBaseBundle\View\ExceptionWrapperHandler'
    routing_loader:
        default_format: json
    body_converter:
        enabled: true
        validate: true
    exception:
        codes:
            'Doctrine\ORM\EntityNotFoundException': 403
        messages:
            'Doctrine\ORM\EntityNotFoundException': false

```

### NelmioCors Configuration

[](#nelmiocors-configuration)

To support OPTIONS calls from your clients.

```
nelmio_cors:
   defaults:
       allow_credentials: false
       allow_origin: []
       allow_headers: []
       allow_methods: []
       expose_headers: []
       max_age: 0
       hosts: []
       origin_regex: false
   paths:
       '^/api/':
           allow_credentials: true
           allow_origin: ['*']
           allow_headers: ['*']
           allow_methods: ['POST', 'PUT', 'GET', 'DELETE', 'OPTIONS']
           max_age: 0

```

### Security.yml Configuration

[](#securityyml-configuration)

```
providers:
    braune_digital_api_base:
            id: braune_digital_api_base.security.apikey_user_provider
    firewalls:
        api_doc: #Open API Documentation
            pattern: ^/api/doc
            anonymous: true
            security: false
        api_login:
            pattern: ^/api/v1/login$
            anonymous: true
        api_password_reset:
            pattern: ^/api/v1/password-((request$)|(reset$))
            anonymous: true
        api: #Secured API-Area
            pattern: ^/api
            stateless: true #we are using tokens
            simple_preauth:
                authenticator: braune_digital_api_base.security.apikey_authenticator #use apikeys for authentication
            provider: braune_digital_api_base #use apikeys for authentication

```

Usage
-----

[](#usage)

### BaseApiController

[](#baseapicontroller)

The BaseApiController provides the underlying logic to create api-endpoints fast and easy: Just extend the *BrauneDigital\\ApiBaseBundle\\Controller\\BaseApiController* and add your functions:

```
