Download the PHP package braune-digital/api-base-bundle without Composer
On this page you can find all versions of the php package braune-digital/api-base-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download braune-digital/api-base-bundle
More information about braune-digital/api-base-bundle
Files in braune-digital/api-base-bundle
Package api-base-bundle
Short Description Api bundle
License MIT
Informations about the package api-base-bundle
BrauneDigitalApiBaseBundle
This Symfony-Bundle uses FOS Rest and provides Basic Api functionality
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
- FOSRestBundle
- WhiteOctoberPagerFantaBundle
- FOSUserBundle (for now)
- JMSSerializerBundle (optional)
Installation
Download using composer:
And enable the Bundle in your AppKernel.
You may use the BaseApiController without registering the bundle too.
Configuration
DefaultConfiguration
FOSRest Configuration
NelmioCors Configuration
To support OPTIONS calls from your clients.
Security.yml Configuration
Usage
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:
You will have to specifiy a Repository and you may need to override the function, if you want to create or update entities.
Security System
To restrict the access to single resources you will need to use symfony voters. Take a look at the BrauneDigital\ApiBaseBundle\Security\Authorization\Voter\BaseCrudVoter which specifies the attributes that are used for the corresponding routes.
Filter the ListAction
To filter list actions, one can override the method. The querybuilder can be customized before returning.
Serialization Groups (JMSSerializerBundle required)
Serialization Groups are used by the JMS Serializer to get a better control over the serialization process.
In your controller
You can easily Add Serialization Groups using or set them by calling .
Using the API-Request Header
Clients can also set serialization Groups by setting the header in the request. The Header may be a simple string, comma delimited or an array of strings.
Api-Key Authentication
In order to use api-tokens, you have to add a token to your User-Class:
And add your DB-Mapping (e.g. DoctrineORM):
Module Access
This Bundle provides a Module-Access Annotation, which can be used to restrict the access of specific routes to certain Roles. In contrast to the Symfony Voting system, this is based on api-endpoints and not on ressources. Import the annotation:
Add your modules:
Or if you only use a single module:
If the user has access to one of the modules, access will be granted. Define the Modules in your configuration:
Example:
Variable Configuration
You can set the _braune_digital_api_base_config attribute in your request to append your custom configuration (braune_digital_api_base.configuration) to your response:
The configuration will be available under the key configuration in your response.
Suggestions
Api-Documentation
We suggest the usage of NelmioApiDocBundle for a clean and easy to use api documentation.
JMSSerializerBundle
TODO
- Check for FOSUserBundle before initializing services
All versions of api-base-bundle with dependencies
nelmio/cors-bundle Version ^1.4.0
friendsofsymfony/rest-bundle Version ^2.0
symfony/security Version ~3.0