2017 © Pedro Peláez
 

library api

image

jdecano/api

  • Friday, September 26, 2014
  • by jdecano
  • Repository
  • 4 Watchers
  • 4 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

LaravelRESTAPIGenerator

A simple package that will help you save your time to create a basic RESTful API for Laravel., (*1)

How to Install

  1. First clone this package.
  2. Edit your app.php and 'Jdecano\Api\ApiServiceProvider' to your available service providers.
  3. Publish the config "php artisan config:publish jdecano/api"

Usage

php artisan api:make

Eloquent Model e.g User: User

Api Version e.g 1.0: 2.0

Configuration

The configuration is at app/config/packages/jdecano/api/paths.php, (*2)

return [
    'controller_target_path'   => app_path('controllers'),
    'routes_file'              => app_path('routes.php')
];

Example Output

After your run the command it will generate the following., (*3)

  1. If you use User as your model, it will create ApiUserController.php
  2. It will add Route::resource('api/1.0/users','ApiUserController'); at the end of the routes file.

Retrive Users

METHOD - GET, (*4)

PATH - /api/1.0/users, (*5)

PARAMS, (*6)

  1. limit = N, (*7)

  2. index = Where to start, (*8)

  3. where = Find by column e.g first_name|=|Dave, (*9)

  4. like = Search by column e.g first_name=Dave, (*10)

RETURNS - JSON, (*11)

Create User

METHOD - POST, (*12)

PATH - /api/1.0/users, (*13)

PARAMS - The column names. Note : Make sure your columns are fillable., (*14)

RETURNS - JSON, (*15)

Update User

METHOD - PUT/PATCH, (*16)

PATH - /api/1.0/users/{id}, (*17)

PARAMS - The column names. Note : Make sure your columns are fillable., (*18)

RETURNS - JSON, (*19)

DELETE User

METHOD - DELETE, (*20)

PATH - /api/1.0/users/{id}, (*21)

RETURNS - JSON, (*22)

Authentication

Wrap your routes with a filter. Heres an example:, (*23)

Basic HTTP Authentication

// routes.php
Route::group(array('before' => 'auth.basic', function()
{
    // Your route goes here
}));

// filters.php
Route::filter('auth.basic', function()
{
    return Auth::basic('username'); 
});

You can ask authentication from your request header

// routes.php
Route::group(array('before' => 'secure_token', function()
{
    // Your route goes here
}));

// filters.php
Route::filter('secure_token', function()
{
    $username = Request::header('username');
    $token = Request::header('token');

    // Then create some kind of validation here
    // If fails then send a 403 Response
    // Easy!
});

The Versions

26/09 2014

dev-develop

dev-develop

  Sources   Download

The Requires

  • php >=5.4.0

 

The Development Requires

19/09 2014

dev-master

9999999-dev

  Sources   Download

The Requires

  • php >=5.4.0

 

The Development Requires