dev-develop
dev-develop
The Requires
- php >=5.4.0
The Development Requires
dev-master
9999999-dev
The Requires
- php >=5.4.0
The Development Requires
Wallogit.com
2017 © Pedro Peláez
A simple package that will help you save your time to create a basic RESTful API for Laravel., (*1)
php artisan api:make Eloquent Model e.g User: User Api Version e.g 1.0: 2.0
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')
];
After your run the command it will generate the following., (*3)
METHOD - GET, (*4)
PATH - /api/1.0/users, (*5)
PARAMS, (*6)
limit = N, (*7)
index = Where to start, (*8)
where = Find by column e.g first_name|=|Dave, (*9)
like = Search by column e.g first_name=Dave, (*10)
RETURNS - JSON, (*11)
METHOD - POST, (*12)
PATH - /api/1.0/users, (*13)
PARAMS - The column names. Note : Make sure your columns are fillable., (*14)
RETURNS - JSON, (*15)
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)
METHOD - DELETE, (*20)
PATH - /api/1.0/users/{id}, (*21)
RETURNS - JSON, (*22)
Wrap your routes with a filter. Heres an example:, (*23)
// routes.php
Route::group(array('before' => 'auth.basic', function()
{
// Your route goes here
}));
// filters.php
Route::filter('auth.basic', function()
{
return Auth::basic('username');
});
// 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!
});