2017 © Pedro Peláez
 

library lumen-restapi

image

chatbox-inc/lumen-restapi

  • Saturday, October 15, 2016
  • by mikakane
  • Repository
  • 2 Watchers
  • 0 Stars
  • 21 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Lumen Application

Latest Stable Version License composer.lock available, (*1)

Rest API アプリケーション作成用のミドルウェア, (*2)

レスポンス生成の一元化とエラーハンドリングを担う。, (*3)

機能

  • RestAPI Response整形の1極化
  • ExceptionHandlerの搭載

Usage

Exception Handler はデフォルトのものを使用する想定, (*4)

$app->singleton(\Illuminate\Contracts\Debug\ExceptionHandler::class,\App\Exceptions\Handler::class);

対象のルートにミドルウェアを二枚かける, (*5)

ミドルウェアの設定順序には注意すること。, (*6)

$app->group([
    "middleware" => [
        \Chatbox\RestAPI\Http\Middleware\HttpExceptionHandler::class,
        \Chatbox\RestAPI\Http\Middleware\APIResponseHandler::class
        ]
],function($router){
    $router->get("/api/status",function(){
        return [];
    });

    $router->get("/api/missing",function(){
        abort(404);
    });

    $router->get("/api/error",function(){
        throw new \Exception();
    });
});

拡張

全ての例外は一度 HttpRequest で投げられるので、そこから処理してあげると楽だったり。, (*7)

400 系エラー例外はHttpExcepiton 継承で投げると特別処理がかかる。, (*8)

Responseを操作する時

\Chatbox\RestAPI\Http\Response を拡張する。, (*9)

Exceptionsを操作する時

\Chatbox\RestAPI\Exceptions\Handler を拡張する。, (*10)

The Versions

15/10 2016

dev-master

9999999-dev

  Sources   Download

The Development Requires

by Avatar mikakane

01/10 2016

0.0.2

0.0.2.0

  Sources   Download

The Development Requires

by Avatar mikakane

01/10 2016

0.0.1

0.0.1.0

  Sources   Download

The Development Requires

by Avatar mikakane