outlandish/rest-bundle

This package is abandoned and no longer maintained. No replacement package was suggested.
There is no license information available for the latest version (v1.0) of this package.

Provides a REST-like API for the Doctrine entities in a Symfony application.

Installs: 1 319

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 9

Forks: 1

Open Issues: 0

Type:symfony-bundle

v1.0 2014-02-21 15:12 UTC

This package is auto-updated.

Last update: 2022-02-15 15:10:50 UTC


README

The OutlandishRestBundle provides a REST-like API for the Doctrine entities in a Symfony application. It is highly opinionated and requires no configuration which makes it an excellent choice for rapid prototyping with JavaScript frameworks such as Angular, Ember and Backbone.

Features:

  • automatically generates routes
  • uses JMSSerializer bundle
  • uses Symfony validator component
  • serializes errors and exceptions
  • supports Doctrine associations
  • uses JSON only
  • pagination
  • simple data queries using FIQL
  • authentication can be added using the security component

For example if you have Acme\FooBundle\Entity\Bar then you can do the following:

GET /api/bar
// returns [{"id":1, ...}, {"id":2, ...}]

GET /api/bar/1
// returns {"id":1, ...}

POST /api/bar
{"foo":"baz", ...}
// returns {"id":3, "foo":"baz", ...}

PUT /api/bar/2
{"foo":"buzz", ...}
// returns {"id":2, "foo":"buzz", ...}

DELETE /api/bar/3
// returns nothing

GET /api/bar?id=gt=2&foo=baz
// returns [{"id":3, ...}]

GET /api/bar?per_page=2&offset=1
// returns [{"id":2, ...}, {"id":3, ...}]

GET /api/bar/0
// returns [{"message":"Entity not found"}]

POST and PUT requests expect JSON encoded entity data in the request body.

On error, a status code of 400, 404 or 500 is returned and the response body is an array of messages.

Installation

1. Add to composer.json

"require": {
    "outlandish/rest-bundle": "dev-master",
},

2. Run composer update

3. Add to AppKernel.php

public function registerBundles()
{
    $bundles = array(
		//...
        new Outlandish\RestBundle\OutlandishRestBundle(),
    );

    return $bundles;
}

5. Edit app/config/routing.yml

#...

outlandish_rest:
	resource: .
	type: outlandish_rest
	prefix: /api