PHPackages                             kron0s/silex-rest - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. kron0s/silex-rest

ActiveLibrary[API Development](/categories/api)

kron0s/silex-rest
=================

RestApplicationServiceProvider for Silex

08PHP

Since May 15Pushed 11y ago1 watchersCompare

[ Source](https://github.com/Kron0S/silex-rest)[ Packagist](https://packagist.org/packages/kron0s/silex-rest)[ RSS](/packages/kron0s-silex-rest/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

RestApplicationServiceProvider
==============================

[](#restapplicationserviceprovider)

[![Build Status](https://camo.githubusercontent.com/0d73f3f8894ce522ec8e5e51b5ed7ce8070e045aec71bd62dfda7bfdc2d5d34c/68747470733a2f2f7472617669732d63692e6f72672f746972616574682f73696c65782d726573742e706e67)](https://travis-ci.org/tiraeth/silex-rest)

**RestApplicationServiceProvider** for Silex gives developers ability to rapidly create REST applications.

Few words about the conversions are needed. This provider gives you a service to build RESTful routes faster and more consistently across the whole application. While you can create `GET`, `POST`, `PUT`, `PATCH`, and `DELETE` actions, not all can be used with individual items or collections. The endpoint should be defined as a plural name of the item type, e.g. `/users` (but you are not limited by the provider and can use whatever convention you like).

- `GET` can be used to fetch the whole collection under `/users` or a single object under `/users/{id}`,
- `POST` can be used to insert new item under `/users`,
- `PUT` can be used to fully update existing item under `/users/{id}`,
- `PATCH` can be used to partially update existing item under `/users/{id}`,
- `DELETE` can be used to remove existing item under `/users/{id}`.

Unfortunately there is no option to automatically create custom route for `PATCH` action, e.g. `/users/{id}/activate`, but you can still do it manually by adding such route to `$app`.

The library requires you to have `ServiceControllerServiceProvider` enabled because I recommend you to use a class for a resource's controller. This way you can keep your application well-organized and reuse the controllers in Symfony2, for instance. And if you decide to keep your controllers with Silex only, you can use `ApplicationAwareController` which implements `disable()` to fastly throw 404 in case of your will to hide some actions from users, and delegates method calls to `$app` (passed by constructor) if needed.

Installation w/ Composer
------------------------

[](#installation-w-composer)

1. Add requirement using CLI: `php composer.phar require mach/silex-rest:dev-master`.
2. Update the requirement `php composer.phar update mach/silex-rest`.

Alternatively you can add the requirement manually:

```
{
    ...
    "require": {
        ...
        "mach/silex-rest": "dev-master",
        ...
    },
    ...
}
```

Usage
-----

[](#usage)

### Registering the provider

[](#registering-the-provider)

```
