如何构建这些REST API端点

huangapple go评论73阅读模式
英文:

How would you structure these rest api endpoints

问题

让我们假设您有4种类型的数据,它们在网站的4个页面上以类似的方式显示,例如视频、文章、帖子等。

您会为每种类型分别创建路由,以获取最近的10个数据,例如/type1/getall/type2/getall等吗,

还是会创建一个路由,比如getAllByType,该路由接受类型作为参数,并返回相应的数据。

感谢您的建议。

英文:

Let's say you have 4 types of data that are displayed similarly across 4 pages of a website like videos, articles, posts, etc.

Would you have individual routes to get the most recent 10 for each like /type1/getall, /type2/getall, etc...,

Or would you have one route like getAllByType that takes the type as a param and returns the respective data.

Thanks for your input

答案1

得分: 1

第二种定义通用路由getAllByType的方法是最常用和推荐的格式,因为这样你的路由结构更清晰,还可以避免冗余代码。希望这有所帮助。

英文:

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. Hope it helps.

huangapple
  • 本文由 发表于 2023年1月8日 10:16:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/75045107.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定