简体   繁体   English

您将如何构建这些 rest api 端点

[英]How would you structure these rest api endpoints

Let's say you have 4 types of data that are displayed similarly across 4 pages of a website like videos, articles, posts, etc.假设您有 4 种类型的数据,它们在网站的 4 个页面上以类似方式显示,例如视频、文章、帖子等。

Would you have individual routes to get the most recent 10 for each like /type1/getall , /type2/getall , etc...,您是否有单独的路线来获取最近的 10 条路线,例如/type1/getall/type2/getall等...,

Or would you have one route like getAllByType that takes the type as a param and returns the respective data.或者您是否有一条像getAllByType这样的路线,它将类型作为参数并返回相应的数据。

Thanks for your input感谢您的输入

2nd method of defining a common route getAllByType with a param is the most used and recommended format because that way your routes structure is clean and it also avoids Redundant code.使用参数定义公共路由 getAllByType 的第二种方法是最常用和推荐的格式,因为这样你的路由结构是干净的,它也避免了冗余代码。 Hope it helps.希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM