php zend,larvel 中的api.php_laravel route api.php 与 web.php 的区别

 2023-09-23 阅读 22 评论 0

摘要:如果是一个纯粹的网站项目,只需要使用 web.php 里的路由就可以了。ajax 需要使用到的 route 也是定义在 web.php 中。如果是一个非网页项目,例如微信小程序,Android / iOS APP 项目,或者给三方开发者提供接口,则应该使用 api.php。因为 co

如果是一个纯粹的网站项目,只需要使用 web.php 里的路由就可以了。ajax 需要使用到的 route 也是定义在 web.php 中。

如果是一个非网页项目,例如微信小程序,Android / iOS APP 项目,或者给三方开发者提供接口,则应该使用 api.php。因为 cookie 那一套并不适用。

Web 路由使用了 web middlewareGroups 。包含类似 Session 及 CSRF 保护,而网页 ajax 同意需要 CSRF 保护。

API 路由使用了 api middlewareGroups

参考 app/Http/Kernel.php

php zend、protected $middlewareGroups = [

'web' => [

\App\Http\Middleware\EncryptCookies::class,

\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,

\Illuminate\Session\Middleware\StartSession::class,

// \Illuminate\Session\Middleware\AuthenticateSession::class,

php框架laravel,\Illuminate\View\Middleware\ShareErrorsFromSession::class,

\App\Http\Middleware\VerifyCsrfToken::class,

\Illuminate\Routing\Middleware\SubstituteBindings::class,

],

'api' => [

'throttle:120000,1',

php laravel、'bindings',

],

];

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/1/89184.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息