英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论