Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

Im0rtality/rest-api-bundle

Repository files navigation

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. Have your entities (for now only Doctrine is supported)
  2. Configure bundle

Scrutinizer Code Quality Build Status SensioLabsInsight

Installation

1. Install via Composer

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

2. Activate it

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

3. Register routes

Add following to your routing configuration:

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. Disable security for API route

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.

Configuration

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

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:

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

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

About

RESTful API bundle

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages