2017 © Pedro Peláez
 

library rest-api-bundle

REST API Bundle

image

im0rtality/rest-api-bundle

REST API Bundle

  • Saturday, September 27, 2014
  • by Im0rtality
  • Repository
  • 1 Watchers
  • 0 Stars
  • 247 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 6 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

REST API Bundle

This bundle is a RESTful API building tool making process as fast as possible. For example, to achieve simple CRUD you only need to:, (*1)

  1. Have your entities (for now only Doctrine is supported)
  2. Configure bundle

Scrutinizer Code Quality Build Status SensioLabsInsight, (*2)

Installation

1. Install via Composer

$ composer require "im0rtality/rest-api-bundle:dev-master"

2. Activate it

Enable bundle in kernel:, (*3)

// 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(),
    );
}

3. Register routes

Add following to your routing configuration:, (*4)

im0rtality_api:
    resource: "@Im0rtalityApiBundle/Resources/config/routing.yml"
    prefix:   /api

4. Configure FOSUserBundle's security

Described in details https://github.com/FriendsOfSymfony/FOSUserBundle/blob/1.3.x/Resources/doc/index.md#step-4-configure-your-applications-securityyml, (*5)

5. Disable security for API route

Add following to your security configuration:, (*6)

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., (*7)

Configuration

You can find minimal sample app with configuration and everything in tests directory of this project (maintained for behat tests), (*8)

Example configuration:, (*9)

# 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

Testing

Most of code is covered with PHPSpec internally and other part is coverted externaly with Behat. To run tests you need to execute following:, (*10)

# install vendors
$ composer install
$ cd test; composer install

# run the tests
$ bin/phpspec run
$ cd test; bin/behat

The Versions