2017-04-21 5 views
1

私はちょっと混乱しています。私はログイン、登録、ログアウトを持つWebアプリケーションを持っています。いくつかのダッシュボードビューなど(CRUD)、私もこのアプリケーションのAPIを作成したい。第三者が使用するようなAPILaravel:ルートディレクトリのApi.php

、レコードを更新することができ、レコードを削除することができますなど

実際にCRUDのためのモバイルアプリで使用することができますいくつかの方法があるはずです。

私はそのルート/ api.phpを持っていることを知っていますが、それを使用するときはかなり混乱しています。シナリオを説明してください、私は空白です。

更新:

シナリオ

アプリケーション持つビュー、認証システムなど、アンドロイドアプリは、同じアプリケーション上でCRUD操作を実行することができますどのように?

+0

私はあなたが私たちはそれを参照することができますがしたい単純なシナリオと結果を提供することができれば、それは良いだろうと思います。 –

+0

@AntonisTsimourtos質問が更新されました。 – Gammer

答えて

1

1.ウェブルーティングでは、セッション状態、CSRF保護が使用されます。それは、セッション状態、CSRF保護を使用していないAPIルーティングを意味するのですか?

すべて可能ですが、必須ではありません。あなたはまだセッションなどを使用することができますが、これはRESTの原則違反です。

2.laravel 5.3では、別のWebとAPIルーティングを使用していますが、利点はありますか?

あなたの便宜のためです。 Laravel 5.2では、['web']や['api']のようなルートのミドルウェアを指定する必要がありますが、これはもう必要ありません。区切られたファイルに格納された5.3のルートでは、経路ミドルウェアは不要です。

0
If you are specifying routes in api.php, you will need to use the auth:api middleware. For example: 

Route::group(['middleware' => ['auth:api']], function() { 
     Route::get('/test', function (Request $request) { 
      return response()->json(['name' => 'test']); 
     }); 
    }); 

Notes about Token auth and Laravel 5.3: 

If you've setup laravel's default auth system, you will also need to add a column for api_token to the user table. If you are using DB seeders, you might want to add something like: $table->char('api_token', 60)->nullable(); to your users table seeder. Alternatively just add the column manually and fill that column with a random 60-char key. 
When making the request, you can add the api_token as a URL/Querystring parameter like so: domain.com/api/test?api_token=[your 60 char key]. You can also send the key as a header (if using Postman or similar), i.e: Header: Authorization, Value: Bearer [your 60 char key]. 
I order to get a useful error if the token is incorrect, also send the following header with all requests: Header: Accept, Value: application/json. This allows the expectsJson() check in the unauthenticated() function inside App/Exceptions/Handler.php to work correctly. 
関連する問題