dboho/slim3-rest-controller

Simple REST controller for Slim3

v0.7.4 2020-07-22 07:44 UTC

This package is auto-updated.

Last update: 2024-05-07 20:14:52 UTC


README

Travis branch Codecov Software License

Dependencies

Usage

// dependencies container
$container = $app->getContainer();

$container[TableController::class] = function ($c) {
    $pdo = new PDO('sqlite:database.db');
    $dataAccess = new DataAccess($pdo);
    return new TableController($dataAccess);
};

// routes for tables books, videos and images
$app->group('/api/{table:books|videos|images}', function () {

    // get all entries in books or a subset selected with query-parameters
    $this->get('', TableController::class . ':getAll');
    
    // get one entry
    $this->get('/{id:[0-9]+}', TableController::class . ':get');
    
    // add one entry
    $this->post('', TableController::class . ':add');
    
    // update one entry
    $this->put('/{id:[0-9]+}', TableController::class . ':update');
    
    // update all entries or a subset selected with query-parameters
    $this->put('', TableController::class . ':update');
    
    // delete a specific entry
    $this->delete('/{id:[0-9]+}', TableController::class . ':delete');
    
    // delete all entries or a subset selected with query-parameters
    $this->delete('', TableController::class . ':delete');
});

Installation

The recommended installation method is via Composer.

In your project root just run:

$ composer require dboho/slim3-rest-controller