This bundle is a RESTful API building tool making process as fast as possible. For example, to achieve simple CRUD you only need to:
- Have your entities (for now only Doctrine is supported)
- Configure bundle
$ composer require "im0rtality/rest-api-bundle:dev-master"
Enable bundle in kernel:
// app/AppKernel.php
<?php
public function registerBundles()
{
$bundles = array(
// ...
// this bundle depends on following two
new JMS\SerializerBundle\JMSSerializerBundle(),
new FOS\UserBundle\FOSUserBundle(),
new Im0rtality\ApiBundle\Im0rtalityApiBundle(),
);
}
Add following to your routing configuration:
im0rtality_api:
resource: "@Im0rtalityApiBundle/Resources/config/routing.yml"
prefix: /api
Described in details https://github.com/FriendsOfSymfony/FOSUserBundle/blob/1.3.x/Resources/doc/index.md#step-4-configure-your-applications-securityyml
Add following to your security configuration:
security:
role_hierarchy:
# Simple admin/user configuration
ROLE_OWNER: ROLE_USER
ROLE_ADMIN: ROLE_OWNER
access_control:
# API bundle takes care of security
- { path: ^/api, role: IS_AUTHENTICATED_ANONYMOUSLY }
Heads-up!
ROLE_OWNER
should not be set on user explicitly. It is added to user roles (in bundle scope only) internally.
You can find minimal sample app with configuration and everything in tests directory of this project (maintained for behat tests)
Example configuration:
# app/config/config.yml
im0rtality_api:
acl: api_acl.yml
mapping:
user: 'Acme\DemoBundle\Entity\User'
data:
type: orm
ownership:
'Acme\DemoBundle\Entity\User': id
key | description |
---|---|
acl | Relative file path which contains ACL configuration stored in YAML format |
mapping | Aliases to your entity used in URL |
data.type | Data source (right now only orm is supported) |
ownership | Entity class name and field linking given entity to it's "owner" user |
Most of code is covered with PHPSpec internally and other part is coverted externaly with Behat. To run tests you need to execute following:
# install vendors
$ composer install
$ cd test; composer install
# run the tests
$ bin/phpspec run
$ cd test; bin/behat