2017 © Pedro Peláez
 

library laravel-restapi

Quick but dirty setup a RESTful API project with Laravel, be evil! ;-)

image

khsing/laravel-restapi

Quick but dirty setup a RESTful API project with Laravel, be evil! ;-)

  • Monday, July 30, 2018
  • by khsing
  • Repository
  • 1 Watchers
  • 2 Stars
  • 266 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 6 Versions
  • 16 % Grown

The README.md

laravel-restapi

Intro

This package make OAuth2.0 client credentials able to assign User., (*1)

Feature

  • client ID support Hashids to encrypt real ID.

Installation

  • Require this package
composer require khsing/laravel-restapi
  • modify config/app.php, add it providers with following lines
Khsing\Restapi\OAuth2ServiceProvider::class,
Khsing\Restapi\RestapiServiceProvider::class,

  • execute php artisan migrate
  • execute php artisan vendor:publish, (*2)

  • Need follow laravel/passport setup, (*3)

Since Laravel 5.5 LTS, passport would specific route register, can custom in app/Providers/AuthServiceProvider.php, (*4)

Passport::routes(function ($router) {
    $router->forAccessTokens();
    $router->forTransientTokens();
});

Configuare

Support following configure options., (*5)

  • enable_hashids, boolean, true/false
  • hashids_salt, salt of hashids, NEED REPLACE WITH YOURS.
  • hashids_length, length of hashids
  • hashids_alphabet, alphabet of hashids

Usage

  • create a client app id and secret.
php artisan passport:client

fill user id, client name and get client secret., (*6)

  • Modify routes/api.php
Route::get('/user', function (Request $request) {
    return $request->user();
})->middleware('auth:api');

Now, access /api/user will get user's infomation., (*7)

btw. Postman is great tools. And the most great part is it's free., (*8)

Intergrate with Dingo/api

  • install dingo/api, composer require dingo/api:2.0.0-alpha1
  • add dingo to providers, Dingo\Api\Provider\LaravelServiceProvider::class,
  • php artisan vendor:publish
  • modify app/Http/Kernel.php with following lines
    protected $middlewareGroups = [
        ...
        'api:auth' => [
            'auth:api',
            'api.auth',
        ],
    ]
  • modify config/api.php auth part
    'auth' => [
        'restapi' => \Khsing\Restapi\DingoAuthServiceProvider::class,
    ]
  • example of dingo/api, in routes/api.php same function
$api = app('Dingo\Api\Routing\Router');
$api->version('v1', ['middleware' => 'api:auth'], function ($api) {
    $api->get('user', function (Request $request) {
        return $request->user();
    });
});

License

This library following MIT License, please keep License file., (*9)

Contact

Guixing:, (*10)

The Versions

30/07 2018

dev-master

9999999-dev

Quick but dirty setup a RESTful API project with Laravel, be evil! ;-)

  Sources   Download

MIT

The Requires

 

The Development Requires

by Guixing Bai

14/12 2017

v5.5.1

5.5.1.0

Quick but dirty setup a RESTful API project with Laravel, be evil! ;-)

  Sources   Download

MIT

The Requires

 

The Development Requires

by Guixing Bai

13/12 2017

v5.5.0

5.5.0.0

Quick but dirty setup a RESTful API project with Laravel, be evil! ;-)

  Sources   Download

MIT

The Requires

 

The Development Requires

by Guixing Bai

08/08 2017

v5.4.2

5.4.2.0

Quick but dirty setup a RESTful API project with Laravel, be evil! ;-)

  Sources   Download

MIT

The Requires

 

The Development Requires

by Guixing Bai

21/07 2017

v5.4.1

5.4.1.0

Quick but dirty setup a RESTful API project with Laravel, be evil! ;-)

  Sources   Download

MIT

The Requires

 

The Development Requires

by Guixing Bai

21/07 2017

v5.4.0

5.4.0.0

Quick but dirty setup a RESTful API project with Laravel, be evil! ;-)

  Sources   Download

MIT

The Requires

 

The Development Requires

by Guixing Bai