简体   繁体   中英

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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