gpt4 book ai didi

laravel - 什么是 RESTful 应用程序更好的 url 结构?

转载 作者:太空狗 更新时间:2023-10-29 18:16:17 24 4
gpt4 key购买 nike

我们有一个 Laravel 后端和 Angular2 前端。

哪种URL结构更好:

什么/:id/action
示例:类(class)/2/编辑

(I've seen this version in most blogs and it's Laravel's default convention)

什么/action/:id
示例:类(class)/编辑/2

This version seems to have better protection from "overlapping"
what/:id/action would run into an issue if I would have
course/categories because categories would fall into :id slot.


所有这些 URL 共享相同的方法 (GET),因此结构本身需要足够好。

重叠问题可以通过按正确顺序排列路由或使用
pathMatch: 'full' 来解决,但这意味着模式本身不够好。

抱歉这个有点主观的问题,感谢您提前抽出时间。

最佳答案

最好的方法是使用标准 RESTful controllers and routes :

GET         /photos
GET /photos/create
POST /photos
GET /photos/{photo}
GET /photos/{photo}/edit
PUT/PATCH /photos/{photo}
DELETE /photos/{photo}

关于laravel - 什么是 RESTful 应用程序更好的 url 结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42532971/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com