kohenkatz/laravel-restful

This package is abandoned and no longer maintained. No replacement package was suggested.

Create your own REST API in Laravel. Supports JSON, JSONP, and XML output.

v1.0.2 2014-07-01 04:20 UTC

This package is not auto-updated.

Last update: 2023-09-27 18:16:31 UTC


README

A base controller for laravel that handles formatting.

Installation

Composer

composer require "kohenkatz/laravel-restful"

Once you've grabbed the code, you'll need to add the RoutingServiceProvider to the list of providers in app/config/app.php as follows

'providers' => array(
    ...
  'Kohenkatz\Restful\RoutingServiceProvider',
),

Usage

The concept uses the same principles as laravel's resource routing. Your controller should extend the one in this package. Each action should return an array which will automatically be formatted.

Add the route to app/routes.php:

Route::resource('posts', 'PostsController');

Then add the controller as follows

use Kohenkatz\Restful\RestfulController;

class PostController extends RestfulController {
    public function index() {
        return array(
            array(
                'id' => 1,
                'title' => 'Released a RESTful controller',
            ),
        );
    }
}

Todo

  1. Split the controller down so that the encoding happens elsewhere to allow for easier extending
  2. Add other encoders (php array, csv etc)
  3. Add more documentation
  4. Investigate if traits would be better suited for parts