Skip to content

Latest commit

 

History

History
114 lines (81 loc) · 2.81 KB

README.md

File metadata and controls

114 lines (81 loc) · 2.81 KB

Laravel API Encryption Package

Total Downloads Latest Stable Version Latest Unstable Version License

Ncoder is a simple API call encryption middleware package designed to work on laravel Framework.

Installing Ncoder

install trough Composer.

composer require tetracode/ncoder

Configuration

  • Register Service Provider

Above Laravel 5.5 or higher no need to add service provider

if you are using laravel 5.4 or below add service provider to Config/app.php providers array

'providers' => [
  Tetracode\Ncoder\NcoderBaseServiceProvider::class,
 ],
  • Register Middleware

Add Ncoder middleware to routeMiddleware array in App/Http/Kernel.php

 protected $routeMiddleware = [

 'ncoder'=>\Tetracode\Ncoder\Http\Middleware\EncryptHttp::class,
 'xncoder'=>\Tetracode\Ncoder\Http\Middleware\ForceEncryptHttp::class,
 ]
  • Publishing Config file

php artisan vendor:publish --tag ncoder-config
  • Generate Secret Key

php artisan ncoder:secret

Middleware Types

ncoder : this will encrypt response only requested in front end. xncoder : this will encrypt response no matter requested in front end or not.

Usage

Route

Route::middleware('ncoder')->post('api-endpoint', 'ApiController@store');

//Force Encrypt Response
Route::middleware('xncoder')->post('api-endpoint', 'ApiController@store');

Route::group(['middleware' => ['ncoder']], function () {
   Route::post('api-endpoint', 'ApiController@store');
});

//Force Encrypt Response
Route::group(['middleware' => ['xncoder']], function () {
   Route::post('api-endpoint', 'ApiController@store');
});

Controller

class UserController extends Controller {

    public function __construct() {
        $this->middleware(['ncoder']);
    }

    public function index() {
         return response()->json(User::all());
    }
}

OR

class UserController extends Controller {

    public function __construct() {
        $this->middleware(['xncoder']);
    }

    public function index() {
        return response()->json(User::all());
    }
}

Credits

Vue Package

License

The MIT License (MIT). Please see License File for more information.